Java Primary Knowledge collection (List,set,map)

Source: Internet
Author: User

There are three types of Java collections: List,set,map. List and set inherit the collection interface. Difference (list can add duplicate objects and sort by index position; Set does not have these two characteristics ).

Map is the value inside the key operation, which is the paired object. Put into the object, get to remove the object.

In addition: Colletion does not have random access to the Get () method because collection also includes set, and set has its own internal order. therefore, to examine the collection element, you must use the iterator object.

1, List has ArrayList (like array form for storage) and LinkedList (linked list form)

2, set specific implementation has hashset, TreeSet and Linkedhashset

1 ImportJava.util.*;2 3  Public classBasic {4      Public Static voidMain (string[] args) {5Collection<string> Collection =NewHashset<string> ();//hashset up, and use generics6Collection.add ("AAA");7Collection.add ("BBB");8Collection.add ("CCC");9Collections.addall (Collection, "E", "FFFF", "AAA");//using the AddAll method of the collection in the Java.util package, it is possible toTen                                                     //add data, but using Collection.add to do so will cause an error. OneIterator<string> it = Collection.iterator ();//using the iterator method, the method returns a iterator that moves between the elements of the container. A          while(It.hasnext ()) -         { -System.out.print (It.next () + ""); the         } -System.out.print ("\ n" +collection); -     } -}

Java Primary Knowledge collection (List,set,map)

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.