For a while, we've learned and summed up the list and map implementation classes. Next, we start to learn set. I believe that after learning map, it will be much easier to learn set. This article mainly introduces the whole structure of set. The overall structure of the set
The set interface inherits the collection interface. Feature is not to save duplicate elements.
Abstractset
is an abstract class that inherits from Abstractcollection and implements set. Abstractcollection provides the backbone implementation of the set interface, minimizing the work required to implement this interface.
SortedSet
Further provides a set for the overall ordering of elements. These elements are sorted by their natural order, or by the comparator that are usually provided when an ordered set is created. The set iterator iterates through the set in ascending order of elements. Provides some additional actions to take advantage of this sort.
Navigableset
Extended SortedSet with a navigation method that reports the closest match for a given search target.
HashSet
Relying on the implementation of a hash table is actually a HashMap instance. It does not guarantee the iteration order of the set, especially it does not guarantee that the order is immutable. This class allows null elements to be used.
TreeSet
Navigableset implementation based on TreeMap. The elements are sorted using the natural order of the elements, or sorted according to the comparator provided when the set was created, depending on the constructor method used.
Linkedhashset
hash table and link list implementations of set interfaces with predictable iterative order. Inherits HashSet, has the HashSet query speed, maintains a double link list running on all entries. This list of links defines the sequence of iterations, that is, the order in which elements are inserted into the set (the insertion order). Note that the insertion order is not affected by elements that are reinserted in the set. The order of the element insertion is displayed.
This article has been included in the JAVA8 container source code notes column.