Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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


Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 528

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.


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

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..
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:
subject: hashCode()
jQuery in Action, 3rd edition