An overview of the

HashSet is implemented based on HashMap, and the underlying key of HashMap is used to store data, so that the elements are not repeated. Therefore, the implementation of HashSet is relatively simple. Basically, it is completed by directly calling the relevant methods of the underlying HashMap.

 

We construct a HashSet by creating a HashMap:

 

Basic operation

1. Add operations

 

2. Delete the vm

 

3. The iterator

 

The other methods basically call the HashMap method


Since a HashSet is implemented based on a HashMap, the elements put in also override the equals and hashCode methods.