This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Beginning Java 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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "hashcode()?" Watch "hashcode()?" New topic
Author

hashcode()?

Shyam Purkayastha
Ranch Hand

Joined: Jan 15, 2001
Posts: 57
Hi all
What is the use of hashcode() function?
Is it related to hashtable class ?
please help
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I am not completely sure, but I think you are on the right track. AFAIK, the HashTable and related classes from the Container API use the hashcode() function when it stores an object.


Java API Documentation
The Java Tutorial
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
It is used by any class that stores objects by using the hash code.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jeremy Thornton
Ranch Hand

Joined: Feb 21, 2002
Posts: 91
A hashcode is usually used as an efficient way of searching for stored objects.
Say you have a list of 1000 names, it would take a reasonable amount of time to search for the name "Jeremy Thornton" in the list.
If however you stored the names according to their hashed value (which is what the HashX type containers do) you just search for the hash of "Jeremy Thornton" - an integer - instead.
As integer processing is much faster than string processing the search is much quicker.
Hoper this helps,
Jeremy.
Shyam Purkayastha
Ranch Hand

Joined: Jan 15, 2001
Posts: 57
thanks a lot jeremy
 
wood burning stoves
 
subject: hashcode()?