June 2018
Beginner
722 pages
18h 47m
English
If you are going to use the class you are writing as a key in a Map, implementing both the equals() and hashCode() methods is very important. See the explanation in the preceding section, Why is it called HashSet? In our examples, we have used objects of the Integer class as keys. This class has an implementation of both these methods based on the integer value of the class.
The class that is going to be stored as a value in a Map has to implement the equals() method, at least (see the next subsection, Locate element).
Read now
Unlock full access