wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Query on HashMap mechanism based on hashcode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Query on HashMap mechanism based on hashcode" Watch "Query on HashMap mechanism based on hashcode" New topic

Query on HashMap mechanism based on hashcode

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi All,

In Java HashMap each bucket is assigned a unique identifier and that identifier is the hashcode of the key.
What i means is if the key's hashcode is say 236 then HashMap bucket will find bucket whose identifier is 236 and put key-value pair
in that.

Could anyone please let me know if my above understanding is correct?

If above correct then -

All key value pair with same hashcode will be present in same bucket they might not be equal using equal() method.

Could anyone please confirm on above?

Thanks in Advance.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38033
It depends how many buckets there are. The Map implementation uses an array of buckets, and uses the hash code to find the bucket. Apart from that, I think you are correct.
There was a discussion about that recently: try here. That will probably answer some of your question, so if there is anything you still need to know, please ask again.
I agree. Here's the link: http://aspose.com/file-tools
subject: Query on HashMap mechanism based on hashcode
Similar Threads
Help needed in understanding the hashCode() method
how to iterate a hashmap with key hashmap
Hashmap doubt from K&B
Using object as keys in maps
working of map?