In java equals() and hashcode() play important role , but how? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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