Rikesh Desai wrote:Oh ok.
So does this mean, (as Harikrishna pointed out), that we need to use HashCode implementation just for HashSet, HashTable and HashMap?
Wont we need to implement it for TreeMap too?
Hi Rikesh, Christophe and Himanshu are saying something like this. Add this code to the program.
Do you see, we are getting 2 different outputs (may differ in your system), which it should NOT be as per contract. We need to implement hashCode() wherever you write equals() method. That's why
String and wrapper classes implements these 2 methods.