+ 1

In java equals() and hashcode() play important role , but how?

12th Feb 2017, 8:06 AM
Abhishek C Prajapati
Abhishek C Prajapati - avatar
2 Answers
+ 2
. equals() check if two strings or any type of var is equal which in java you can't check using '==' etc string x, y; x = "mark" ; y = "mark" ; if you try printing 'x==y' it will return false if you try printing 'x. equals(y)' it will return true as for hashcode a google search will help here some things about hashcode: http://eclipsesource.com/blogs/2012/09/04/the-3-things-you-should-know-about-hashcode/
12th Feb 2017, 8:40 AM
TheoVal
TheoVal - avatar
+ 1
The equals() method in java is used to compare two objects. And for hashcode in java, every class implicitly or explicitly provides a hashCode() method, which digests the data stored in an instance of the class into a single hash value (a 32-bit signed integer).
12th Feb 2017, 8:35 AM
Varun Moghe
Varun Moghe - avatar