Summary of Java Collections

Source: Internet
Author: User
Tags set set

Collection Sub-interface:
---List interface (an orderly, repeatable element), also known as a "dynamic array"The ---vector ( the old implementation class ) is thread-safe (no matter what it is) ---arrayList (The primary implementation class of the list ) ( the underlying is implemented with an array ) ---linkedlist ( The underlying is implemented with a linked list ) ( This is recommended for frequent insert and delete operations ) contains () methodThe equals method of this class is called when the object element is judged to be the same in the collection, so it is generally required to override the Equals method when it is stored in the collection.

---Set interface (elements are unordered and cannot be repeated unordered but not random, In addition, disorder means that the element is stored in the underlying position without regularity.) similar to the high school collection,The order in which the ---HashSet(the primary implementation class) is traversed and the order in which it is added is different The order in which ---linkedhashset is traversed is the same as the order in which it was added, the order of additions maintained, and the insertion performance is lower than hashset, but the traversal performance is the best c0>---SortedSet---TreeSet features: The elements added to the ① must be of the same type, either full integer or I am all string type. ② can be traversed in the specified order, as if the string were traversed in small to large order .③ for custom class traversal, you must implement the Sort method, otherwise treeset do not know what method to traverse the element, so plug in, ④ custom class There are two methods, 1, natural sort 2, custom sorting (custom row Order) about these two sort reference notes (natural sort and custom sort in TreeSet)⑤ to add elements to the TreeSet will first compare CompareTo () method, once returned 0, although the two objects only this property is the same, but the program will still think that the two elements are the same, so the subsequent element cannot be inserted into the collection! The element class added to TreeSet must guarantee the CompareTo () method, the Hashcode () method, and the Equals () method consistent
The elements in the set's set must implement the Equals () method and the Hashcode () method to guarantee the non-repeatability of the set set, and the Equals () method and the Hashcode () method must be consistentThe storage in set is using a hashing algorithm. In the time of deposit in the first caller Hashcode () method to hash value, this hash value determines the location of the element, if there is an element in this position to determine whether equals (), if equals cannot be stored in, if only the Equals () method is overridden, The hash value is still different or cannot be stored in the set



Map Sub-interface: A set of key-value pairs similar to a high school function where key is the value that is stored using Set collection ---HashMap (Main implementation Class) ---linkedhashmap and linkedhashset similar ---TreeMap natural sort, custom sort (for key)---HashTable (thread safe, old class not used) (subclass properties)
map traversal: ① traversal key set using Set key = Map. KeySet (); Just walk through the key.② iterates over the value set, using collection value = Map.values ();③ Traverse Key-value to

Collections: A tool class for manipulating collection and maps. refer to Javaapi documentation for detailed methods

Summary of Java Collections

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.