java-Collection (i)

Source: Internet
Author: User

Tips for using collections:
See array is the structure of arrays, there is a corner mark, query fast.
See link is the linked list structure: The deletion speed is fast, and there are unique methods. AddFirst; Addlast;?removefirst (); Removelast (); GetFirst (); GetLast ();
See hash is a hash table, you want to hash value, it is necessary to think of uniqueness, it is necessary to think of the elements deposited into the structure must cover the Hashcode,equals method.
See tree is a binary tree, it is necessary to think of a sort, you want to use the comparison.


Two ways to compare:
One is comparable: Cover CompareTo method, one is comparator: Overrides compare method.
Linkedhashset,linkedhashmap: These two sets ensure that the hash table is stored in the order and in the order in which it is fetched.
When does the collection work?
When storing an element, use collection.
The map collection is used when there is a mapping between the stored objects.
Guaranteed to be unique, use set. Not guaranteed to be unique, use list.


Collection system: A reference to an object that is stored in the collection (address)
List and set

List:arraylist LinkedList Vector has an index-specific iterator Listiterator
Set:hashset TreeSet

Collections Common Set

ArrayList
To create a collection container
ArrayList al=new ArrayList ()
1. Add elements:
A1.add ("");
A1.add ("");
2. Get length, number of sets
A1.size ();
3. Deleting an element
A1.remove ();
4. Emptying the collection
A1.clear ();
5. Judging
Whether the A1.contains () contains
A1.isempty () is empty
6. Take the intersection
A1.retainall (A2); takes an element of the intersection of two sets.


remove element:
Iterator: The way the collection takes out the elements.
Iterator It=a1.iterator ();
while (It.hasnext ())
{
It.next ();

}

java-Collection (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.