Collection classes are stored in the Java.util package
The first thing to say is collection.
Collection is the basic interface of a collection, and List, Set, and queue inherit from the collection interface (map does not).
There are three main types of Java collections:set,list and Map
Set (SET)
The set has exactly the same interface as the collection, so there is no additional functionality. In fact set is collection, but behaves differently. (This is a typical application of inheritance and polymorphic thinking: behavior that behaves differently.) Set does not save duplicate elements (more responsible for how the elements are judged)
Set: Each element that is stored in the set must be unique because set does not save duplicate elements. The element that joins the set must define the Equals () method to ensure the uniqueness of the object. The set has exactly the same interface as the collection. The set interface does not guarantee the order in which elements are maintained.
HashSet: Set for quick find design. The object that is deposited into the hashset must define HASHCODE ().
TreeSet: The set of the save order, the underlying tree structure. Use it to extract ordered sequences from the set.
Linkedhashset: has hashset query speed, and internally uses the chain list to maintain the order of elements (the Order of insertions). The result is displayed in the order in which the elements are inserted when iterating through the set using Iterators.
List (lists)
List: Order is the most important feature of the list: it guarantees that the elements are in a specific order, that is, the elements in the list are ordered. The list adds a number of methods to the collection, enabling the ability to insert and remove elements into the list (this is only recommended for LinkedList, because it is the storage structure of the linked list) a list can generate Listiterator, which can be used to traverse the list in two directions , you can also insert and remove elements from the middle of the list. The Java list has a total of three implementation classes: ArrayList, vectors, and linkedlist, respectively.
ArrayList: List implemented by arrays (sequential storage, that is, creating a contiguous space within the storage space for storage, it is worth mentioning that if the storage space is full, it will automatically increase the 50%+1 space). Allows for fast random access to elements, but inserts and removes elements into the list is slow (due to sequential storage, if you assume there are 10 elements, you need to delete the 2nd one, then 3,4,5 ... the position of the 10th element needs to move forward, inserting the same). Listiterator should only be used to traverse the ArrayList backward, not to insert and remove elements. Because that's much more expensive than linkedlist.
LinkedList: A linked list storage structure, the cost of inserting and deleting the middle of a list is not significant (because the storage space itself is not contiguous, and the element and the next element are connected by pointers). Random access is relatively slow (because the pointer needs to be moved while the ArrayList is directly accessible to a fixed location), as well as the following methods: AddFirst (), AddLast (), GetFirst (), GetLast (), Removefirst () and Removelast (), these methods (not defined in any interface or base class) make LinkedList available as stacks, queues, and bidirectional queues.
Vector: Also by the array implementation of the list, basically the same as ArrayList, the main advantage of the vector is thread safety, a vector at the same time only one thread to write to it, but because the synchronization of threads need to consume a certain amount of resources, So the speed is not as natural as ArrayList.
Map (map)
Map and collection are juxtaposed in the set frame (i.e., the inheritance collection mentioned above does not include map)
The map stores the key-value pairs, and the previous list and set store only values, and of course, they can be considered as their keys in the collection, but they are essentially different. The map storage element uses the Put method, collection uses the Add method, the Map collection takes out the elements first to the set set, and then iterates through the elements, and also differs in collection. In addition, because the map collection is stored with key-value pairs, the key must be unique, that is, any two keys cannot be the same, but the values can be the same, that is, any two different keys corresponding to the same value. Map
Here to first mention the concept of the hash table: Hash table is also known as a hash list, there are direct translation of the hash table, hash is a special data structure, it is the same as the array, linked list and two-fork sorting tree and other compared with a very obvious difference, it can quickly locate the record you want to find, Instead of being compared to the keywords in the table that exist in the record, find
Hashtable: The underlying is a hash table data structure that threads are synchronous (that is, thread safe) and cannot be stored as null keys,null values. low efficiency, replaced by HashMap.
HashMap: The underlying is a hash table data structure that the thread is not synchronized and can be stored in a null key,null value. to guarantee the uniqueness of the key, you need to override the Hashcode method, and the Equals method.
Linkedhashmap: This sub-class is based on a hash table and incorporates the linked list, improving the efficiency of inserting and deleting elements, while the efficiency of access should also decrease.
TREEMAP: The bottom layer is a two-fork tree data structure. You can sort the keys in the map collection. You need to use comparable or comparator for comparison sorting, but you can also define them to implement special sorting methods.
Reference blog:
Java drill-In-depth understanding of Java collections
Use of Set in Java
A detailed description of the Java map collection
Java Collection related