File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Hashing 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 "Hashing" Watch "Hashing" New topic
Author

Hashing

sandeep Talari
Ranch Hand

Joined: Dec 24, 2007
Posts: 63
please anybody help me regarding the Hashing process , what is the concept behind the hashmap,hashtable and hashset can anybody help in neat explained manner.Point is how hashmap,hashtable and hashset rely on hashing
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

For fast lookups, objects are stored in so-called buckets. Each bucket contains objects with the exact same hash code.

If the value for a key is looked up, its hash code is calculated first. Then the bucket for that hash code is retrieved. This will decrease the number of objects to search through - instead of checking every single object in the map / set, only the objects in the one bucket will be checked. The better your hash code, the better objects are distributed among buckets, and the faster your map / set becomes.

That also shows the reason why the hash code for equal objects should be the same as well - otherwise, the object will not be found. It also shows another issue: you cannot modify objects stored in the map / set (keys for maps only) in such a way that the hash code will change, or it will never be found again.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hashing