t.put(d1,"AIKO");
When this element will be put in TreeMap, equals() will not be called as TreeMap has no element at this time.
t.put(d2,"CLOVER");
When this line called, TreeMap will call
1) d1.hashCode()==d2.hashCode(), this will return true as 7==7 is true, so it will call equals().
2) d1.equals(d2) will be called, this will return false as "AIKO"!="CLOVER".
equals() returns false so it will add d2 in the TreeMap
t.put(d3,"CLOVER");
When this line called, TreeMap will call
1) d1.hashCode()==d2.hashCode(), this will return true as 7==7 is true, so it will call equals().
2) d1.equals(d2) will be called, this will return false as "AIKO"!="CLOVER".
Now again
3) d2.hashCode()==d3.hashCode(), this will return true as 7==7 is true, so it will call equals().
4) d2.equals(d3) will be called, this will return true as "CLOVER"!="CLOVER".
here d2.equals(d3) returns true, so it will not add d3 in the map.
[ January 03, 2009: Message edited by: Punit Singh ]