• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Query on HashMap mechanism based on hashcode

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic