
- Forum
- Programming Talk
- Java
- Difference between hashcode() and equals()...
Difference between hashcode() and equals()...
This is a discussion on Difference between hashcode() and equals()... within the Java forums, part of the Programming Talk category; I have tried so many times to find the difference...but not getting a satisfactory explanation.... can anybody explain with a ...
-
Difference between hashcode() and equals()...
I have tried so many times to find the difference...but not getting a satisfactory explanation.... can anybody explain with a good example??
-
hashcode is an integer number which is provide to each object by jvm note that this is not address of object but for convencing internally they use
equals() is used to compare the objects it returns boolean value
if any doubt then pls ask
-
Compares values for equality. Because this method is defined in the Object class, from which all other classes are derived, it's automatically defined for every class. However, it doesn't perform an intelligent comparison for most classes unless the class overrides it. It has been defined in a meaningful way for most Java core classes. If it's not defined for a (user) class, it behaves the same as ==.
It turns out that defining equals() isn't trivial; in fact it's moderately hard to get it right, especially in the case of subclasses.
-
I think Java will be able to resolve between the two objects using their equals() method
-
05-19-2011, 06:56 AM #5
- Join Date
- May 2011
- Answers
- 5
equals() the name itself is pretty explanatory.
coming to hashcode() , this is a special code given to every object created. the neccesity in giving this code is, in c / c++ we can trace the addres of any variable by using "&" operator. The virus programs are developed with the help of address values, to avoid such things hashcode was introduced , hashcode() it retruns a value which is not the addres value but a unique number assigned to every object.
there is no need of comparision between equals() and hashcode() , they r distinct to each other
ur's
sudheer
-
Sponsored Ads

Reply With Quote





