This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Java in General and the fly likes HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "HashMap" Watch "HashMap" New topic
Author

HashMap

Will Myers
Ranch Hand

Joined: Aug 05, 2009
Posts: 362

Hi,
I have a question about HashMaps. If I have a HashMap and I insert an object that has a hashcode of say 10 will the underlying array of HashEntries have 10 elements even though the map contains just one object?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19932
    
  43

will myers wrote:Hi,
I have a question about HashMaps. If I have a HashMap and I insert an object that has a hashcode of say 10 will the underlying array of HashEntries have 10 elements even though the map contains just one object?


No. The number of buckets is determine by a few conditions. The value of the hashcodes (of the elements) is not one of them.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
Don't get me started about those stupid light bulbs.
 
subject: HashMap
 
It's not a secret anymore!