1 HashSet is the main implementation class, and the methods commonly used in set are defined under collection.
2 Disorder: Disorder! = Randomness. The position of the element in the underlying storage is unordered
Non-repeatability: When adding the same element, the following elements cannot be added
3 Note: To add elements to the set, be sure to override the Equals and Hashcode methods
To guarantee the non-repeatability of the elements in the set.
4 How are elements stored in set? Using a hashing algorithm, like arranging students to sit in different places in the classroom, the elements are stored in different places in memory.
5 When you add an object to a set, you first call the Hashcode () of the class that contains the object, and the hash value of this object determines where the object is stored in set. If there is no object storage at this location, then this object is stored directly in this location, if there is already an object store at this location, and then by Equals () compares two objects are the same, if the same, the subsequent elements cannot be added.
Requirements: Hashcode () method values are consistent with the Equals method.
Set set and Implementation class