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