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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "hashCode()" Watch "hashCode()" New topic
Author

hashCode()

Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

please correct me if i am wrong, but the hashCode method is supposed to generate an integer value which is used to IDENTIFY buckets in a Hashtable or a Map in general? Or is it the key which is used to locate the buckets?

i'm reading it in books but am having abit of trouble, can someone plz explain this to me in THEIR OWN words. Thanks for your time.

Cheers, Marzo.


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA

Live life to an interface, not an implementation!
Marcos Vilela
Greenhorn

Joined: Jul 06, 2005
Posts: 18
The hashcode generate an int that identify in which bucket the object will be and if there are more then one object in the bucket, you are going to use the equals method to find the exactly object that you are looking for.

Correct me if I'm wrong..
Thanks.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Marcos Vilela:
Correct me if I'm wrong..


That is correct, Marcos.

If you're interested, I wrote an article once upon a time regarding Hash Codes. You can find it here. Hopefully, that will help answer any questions you have and, if not, ask some more.


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hashCode()