Set Set
Elements cannot be duplicated, they are unordered.
Method is the same as list
HashSet: No guaranteed set Iteration order, no synchronization, internal data structure is a hash table
If you save a custom object, you need to override the Equals and Hashcode methods
Compare Hashcode First, if the hashcode is the same again equals method comparison, if still the same as the judgment element is no longer into the container, that is, the Add () method does not add elements
Linkedhashset: both orderly and unique
TreeSet: The elements in the set collection can be sorted and are not synchronized
The way to judge whether an element is unique is by comparing the method comparable returns 0, and returning 0 is equal
TreeSet How to sort the elements one:
Let the element (deposited object) implement the comparable interface and overwrite the comparable method
Determine size and sort by return value (0, positive, negative)
If a negative number is returned, indicating that the element to be added is greater than the element being compared, place the element you want to add to the right of the binary tree
Instead...
Way two:
If the object does not have a natural sort, you can make the collection itself comparable.
The TreeSet constructor is injected into a class object that implements the comparator interface and overrides the Compare method to sort;
(Note: The second method is used when both methods are in use)
Set of the Java Collection framework