wood burning stoves 2.0*
The moose likes Java in General and the fly likes hashCode()???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "hashCode()????" Watch "hashCode()????" New topic
Author

hashCode()????

raymond yadao
Ranch Hand

Joined: Jan 29, 2001
Posts: 88
What does the method hashCode do? can u give some sample code about hashCode()?
thnks....
raymond
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

It simply returns an integer that can be used as a hash code for that particular object, which can be used by the Java collection classes such as Hashtable.
Moreover, it is required that if objects are equal according to the equals(Object obj) method, the hash code returned by them must be same.
As for examples, in standard Java wrapper class Integer, if you construct an object of class Integer such as -
Integer seven = new Integer(7);
and call seven.hashCode() it will return 7.
You can read about how to implement hashCode() method in your own classses at - http://developer.java.sun.com/developer/Books/effectivejava/Chapter3.pdf
HTH,
- Manish
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hashCode()????
 
Similar Threads
hash code
what is hashcode and equals contract?
Practice Question
basicjava
need help with the space-time continium