Kuldeep Singh DH

Greenhorn
+ Follow
since Apr 02, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kuldeep Singh DH

oh ok sorry for that. actually I used JavaRanch for the first time and I find this question. and It promt me to share my thoughts here. Now I read "How To Answer Questions On Java Ranch". I will take care in future.

But this does not only helpful for the user who actually posted this question but also it helps the people who are new in java and have similar kind of quesion now. Its just my thought. anyway I will care this in future.

Thanks
Kuldeep
14 years ago
The JAVA API documentation states that if two objects are equal, then they must have the same hash code, however the opposite is NOT true. But, when both functions run independently, then why this contract?

There are some myths that equals() calls hashcode() internally or vice-versa, but this is not truth. use of equals is straight forward, and hashCode () is used only for hashing capabilities in hash capable collections(i.e HashMap, HashSet) in java.

hashcode() is used to generate 'hash' which is number that is used to index/locate a memory location in a large list of memories("bucket"). So all the equal objects should be found in same bucket so all equal object should have same hashcode. but opposite is not true because a bucket can contains different objects.
14 years ago