aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes hashCode() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "hashCode()" Watch "hashCode()" New topic
Author

hashCode()

brent spearios
Ranch Hand

Joined: Apr 10, 2002
Posts: 48
Can someone explain what hashCode does, thanks
Steven Wong
Ranch Hand

Joined: Mar 07, 2002
Posts: 295
Hi,
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.
The general contract of hashCode is:
Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.

BTW, I extracted this from the jdk api.
Clement


best regards,<br />Steven<br />SCJP, SCEA
Toby Davis
Ranch Hand

Joined: Apr 09, 2002
Posts: 65
See this thread. Has some links to resources on hashcode implementations.
--


SCJP2 (1.4)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hashCode()