Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

hashcode is calculated on the basis of value object

Hi,

I am reading below link
http://www.java2blog.com/2013/02/difference-between-hashmap-and-hashset.html

I have not understood below point

In this,hashcode is calculated on the basis of value object.Hashcode can be same for two value object so we have to implement equals() method.If equals() method return false then two objects are different.
Read more at http://www.java2blog.com/2013/02/difference-between-hashmap-and-hashset.html#ZZEA3viEKQ7T9uHh.99



what it mean by hashcode is calculated on the basis of value object.

Based on below example
http://www.java2blog.com/2014/07/how-hashset-works-in-java.html

I understood that india printed only once as we have not implemented hashCode and due to that hashCode different for india1 and india2 object so wont bother to check equals.

But original point (hashcode is calculated on the basis of value object) seem reverse of above concept. please advise
SOLUTION
Avatar of gurpsbassi
gurpsbassi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Radek Baranowski
Radek Baranowski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial