| Author |
Need Help in hashcodes
|
Sekhar Choudary
Ranch Hand
Joined: May 03, 2008
Posts: 57
|
|
Can anyone explain the hashCode and equals contract How to choose hashcode values. How the integer literals will be identified in java. Thanks.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16680
|
|
In a nutshell, hashing is a very quick mechanism to distribute objects. It is important because when you have many object that needs to be added, removed, searched, in a collection -- hashing gives a way of doing it without constantly comparing it with other objects in the collection. The purpose of the hashcode is to find a location -- a bucket to place object. Objects that are in different buckets, are by definition, different objects. However, objects that are in the same bucket, doesn't mean they are equal. These must be further checked with the equals() method. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
amit k prabhat
Greenhorn
Joined: Aug 09, 2008
Posts: 6
|
|
hi shekar, For further clarification check the following thread how many string objects will be created
|
 |
 |
|
|
subject: Need Help in hashcodes
|
|
|