Java Foundation Collection Framework

Source: Internet
Author: User

Collections in Java can be divided into two main categories, from the inheritance of classes and the implementation structure of interfaces:

1 inherits from the collection interface, including the list, set and queue interfaces and implementation classes.

2 inherits from the map interface, which mainly contains the collection classes related to the hash table.

  First Class

Collection interface inheritance and implementation structure diagram is as follows:

The green dashed line in the figure represents the implementation, the green solid lines represent the inheritance between the interfaces, and the blue solid lines represent the inheritance between the classes.

List

Commonly used are ArrayList and LinkedList. ArrayList through the array implementation, random access is faster, and delete operation is slow. And LinkedList through the chain list implementation, adding and deleting operations relatively fast, random access is relatively slow. Both are non-thread-safe.

Queue

The LinkedList implements the Deque interface, so LinkedList has a dual-ended queue capability. Priorityqueue internal data structures are heaps, each out-of-queue element is always the largest in the current queue (the Big Top heap) or the minimum (small top heap).

Set

The main difference between set and list is that set does not allow elements to be duplicated, and list allows elements to be duplicated. The difference between HashSet and Linkedhashset is that the latter guarantees that the element order of the element's insert collection is consistent with the output order. The difference between them and TreeSet is that treeset are sorted by comparator, by default in ascending order of the character's natural sequence.

  

  Type II

Map interface inheritance and implementation structure diagram is as follows:

The greatest advantage of a collection of map types is that it is relatively efficient to find and ideally can achieve O (1) time complexity. The most common in map is HashMap. The difference between Linkedhashmap and HashMap is that the order of the elements in the insertion set is consistent with the output order. The difference between the two and TreeMap is that the treemap is sorted according to the key value, and the underlying implementation has an essential difference, such as the HashMap bottom is a hash table, and TreeMap's bottom is a tree. In a multithreaded environment, CONCURRENTHASHMAP is usually used because the hashtable is less efficient.

Resources

The overall structure of the Java collection

Java Foundation Collection Framework

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.