0

What is the difference between hashcode() and equals()?

24th Jan 2017, 10:27 AM
Ahmed Abd Elazeem
Ahmed Abd Elazeem - avatar
3 Answers
+ 1
Uhm, ok. You always should override both of them. Very short (and incomplete) answer: equals() is for comparison of two Objects like in boolean eq = "a".equals(new String("a")); hashCode _and_ equals are needed for Sets and Maps, if you want to know, if they contain a Object.
24th Jan 2017, 11:22 AM
bem
bem - avatar
0
Code says more than a thousand words. I quickly wrote an example for you. Look at my codes, "Difference between equals() and hashCode()" explains it very well.
24th Jan 2017, 11:02 AM
bem
bem - avatar
0
I misunderstood your code could you explain more
24th Jan 2017, 11:12 AM
Ahmed Abd Elazeem
Ahmed Abd Elazeem - avatar