The output of the following code sample is:
{1--e=e2, 2--e1=e1}
package com.sid.practice;
import java.util.HashMap;
import
The java.util.HashMap implementation does not replace the existing key when it is equal to the key supplied in the put() call. So, your third put() checks the existing contents of the map, finds an existing equal key and just updates the associated value.
This illustrates why equals() and hashCode() should generally take all properties into account as objects which are considered equal are considered interchangeable by many of the util classes.