1. Collection framework system diagram
2. Overview of the characteristics of each collection
Interface Collection<E> [Single column collection]
[The root interface of a single-column collection in a collection hierarchy. A collection represents a group of objects called its elements]
【Single column】Interface List<E>
[Ordered collection, allows elements to be repeated, allows multiple elements to be NULL, can control the insertion position of elements, and access elements through indexes]
Class ArrayList<E>
[Controllable size array structure, the default initial capacity is 10. The query speed is fast, and the efficiency of inserting and deleting data is reduced. thread unsafe]
[Controllable size array: When the number of elements in the collection is greater than the length of the current collection array, the capacity will be expanded by 50%]
Class LinkedList<E>
[Doubly linked list structure; allocation of memory space does not have to be continuous; insertion and deletion efficiency is high; query efficiency at both ends is high, but efficiency in the middle is low]
Class Vector<E>
[Controllable size array structure, the default initial capacity is 10. The query speed is fast, and the efficiency of inserting and deleting data is reduced. thread safety]
[Controllable size array: When the number of elements in the collection is greater than the length of the current collection array, the capacity will be expanded by 100%]
[Since thread synchronization will inevitably affect performance, the performance of ArrayList is better than Vector]
【Single column】Interface Set<E>
[Unordered collection, no duplicate elements allowed, single element allowed to be NULL]
Class HashSet<E>
[The bottom layer is implemented based on HashMap . The underlying data structure is a hash table , which allows a single value to be NULL . The default initial capacity is 16 ]
Class LinkedHashSet<E>
[The bottom layer is implemented based on LinkHashMap . The underlying data structure is a hash table + linked list to ensure that the traversal and insertion order are consistent ]
Class TreeSet<E>
[The bottom layer is implemented based on TreeMap , the underlying data structure is a red-black tree , the value cannot be NULL, and the default is natural sorting]
[The type corresponding to the storage element must implement the Comparable interface. As long as it is not a custom type, this interface is basically implemented]
Interface Map<K,V> [Hash set] [Key key——Value value]
[Mapping keys to values, keys cannot be repeated]
Class HashMap<K,V>
[The underlying structure is implemented based on hash table (array + linked list) , both key and value can be NULL , non-thread safe ]
Class LinkedHashMap<K,V>
[The underlying structure is implemented based on hash table + doubly linked list, ensuring that (key) insertion and access sequence are consistent ]
Class TreeMap<K,V>
[The underlying structure is implemented based on red-black trees , the key cannot be NULL, the value can be NULL, and the keys are naturally sorted]
[Red-black tree: also known as red-black binary tree ]
Class HashTable<K,V>
[The underlying structure is implemented by hash table (array + linked list) , neither key nor value can be NULL, thread safe] [ synchronized
Pessimistic Lock ]
Class ConcurrentHashMap<K,V>
[The underlying structure is implemented based on hash table (array + linked list) , replacing HashTable after JDK1.5]
[Before JDK1.8, segmentation lock split the entire bucket array into segments ( Segment
)]
[After JDK1.8, synchronized
and CAS ]