jaffar hussain

Greenhorn
+ Follow
since Jun 01, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by jaffar hussain

Matthew Brown wrote:Using HashMap, it's the keys that are compared, not the values. It's quite happy to have lots of entries with the same value, as long as the keys are unique. And you're using a HashMap<Integer, HashCodeTest_HashMap>.

So in your second code the HashMap doesn't care about the equals() and hashCode() methods of HashCodeTest_HashMap, as your keys are all Integers.



Thank you I tried obj1,obj2,obj3 as keys it worked equals got called thank you once again
12 years ago
I am pasting you two code snippets.

1. Implementing hashcode() and equals() with HashSet:



2. Implementing hashcode() and equals() with HashMap:




My Question is :

While debugging with HashSet line by line I am able to find the flow entering into equals method when its get matched with two equal hashcodes.

But while I am debugging with HashMap line by line I am not able to find the flow entering into equals method when its get matched with two equal hashcodes.


So I am unable to understand how and when exactly equals gets called and why its not getting called with HashMap please somebody explain me this?

Or any link or reference to understand this...

Thanks in advance...
12 years ago