When you want to store and retrieve your custom object as a key in Map, then you should always override equals and hashCode in your custom Object . Eg:
Person p1 = new Person("A",23);
Person p2 = new Person("A",23);
HashMap map = new HashMap();
map.put(p1,"value 1");
map.put(p2,"value 2");
Here p1 & p2 will consider as only one object and map
size will be only 1 because they are equal.