In the general framework for Java Collection Series 01, the schema of the Java collection is described. The main content includes the collection collection and the Map class, while the collection collection can be divided into List (queue) and set (collection).
1. List of the main implementation classes are: LinkedList, ArrayList, Vector, Stack.
LinkedList is a double-ended queue implemented by a doubly-linked list; it is not thread-safe and only applies to single-threaded.
(ArrayList) is an array-implemented queue, which is a dynamic array; it is not thread-safe and only applies to single threads.
Vectors are vector queues implemented by arrays, and it is also a dynamic array, but unlike ArrayList, vectors are thread-safe and support concurrency.
Stack is a stack of vector implementations, and, like vectors, it is thread-safe.
2. Set implementation classes are mainly: Hastset and TreeSet.
HashSet is a collection of non-repeating elements that are implemented through HashMap; HashSet is not thread-safe and only applies to single threads.
TreeSet is also a collection of non-repeating elements, but unlike HashSet, the elements in TreeSet are ordered; it is implemented through TreeMap; TreeSet is not thread-safe, only for single-threaded.
The 3.MAP implementation classes are mainly: Hashmap,weakhashmap, Hashtable and TreeMap.
HashMap is a hash table that stores "key-value pairs"; It is not thread-safe and only applies to single threads.
Weakhashmap is also a hash table; Unlike HashMap, HashMap's "key" is a strong reference type, and Weakhashmap's "key" is a weak reference type, meaning that when a key in Weakhashmap is no longer in use, will be automatically removed from the Weakhashmap. Weakhashmap is also not thread-safe and is only available for single-threaded use.
Hashtable is also a hash table; Unlike HashMap, Hashtable is thread-safe and supports concurrency.
TreeMap is also a hash table, but the "key-value pair" in TreeMap is ordered, it is implemented by the R-b tree (red and black); TreeMap is not thread-safe and only applies to single threads.
For more information on these collection classes, refer to the Java Collection series catalog (category).
For convenience, we will refer to the collection classes described previously collectively as "Java Collection packages ." Java collection packages are mostly "non-thread-safe", although the synchronization classes for Java collection packages can be obtained through methods in the Collections tool class, but the concurrency of these synchronization classes is not very high. In order to better support high concurrency tasks, the concurrency guru Doug Lea adds a corresponding high concurrency-enabled class to the single-threaded class in the Java collection package in the Juc (java.util.concurrent) package. For example, the ArrayList corresponding high concurrency class is the copyonwritearraylist,hashmap corresponding high concurrency class is concurrenthashmap, and so on.
The JUC package uses the framework in the Java Collection package when adding a high concurrency class corresponding to the Java collection package, in order to maintain the consistency of the API interface. For example, Copyonwritearraylist implements the list interface in the Java collection package, HashMap inherits the Abstractmap class from the Java collection package, and so on. since the Juc package uses classes from the Java collection package, it is relatively easy to understand the classes in the Juc package if we understand the concepts of the classes in the Java collection package, and the biggest difficulty in understanding it is how to add support for "high concurrency" to the JUC package!
Java Learning notes