Does HashMap use the hashCode and equals methods of the key or value to store its entries, i.e., which is the class whose hashCode and equals methods we need to override? Should it be the key's class (K), or the value's class (V)?
Does HashMap use the hashCode and equals methods of the key or value to store its entries, i.e., which is the class whose hashCode and equals methods we need to override? Should it be the key's class (K), or the value's class (V)?
The value is essentially irrelevant to the Map itself: it's only the key which is considered by the HashMap when it is deciding where to put the key/value pair within its internal data structure.
However, you might want to override it for the value too, e.g. if you need to do map.values().contains(...).
Your key class needs appropriate overrides for hashCode and equals.
The hash code of the key determines which hash bucket an object should be placed in.
The equals method of the key allows you to distinguish between keys which happen to hash to the same bucket.