aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "HashMap" Watch "HashMap" New topic
Author

HashMap

Will Myers
Ranch Hand

Joined: Aug 05, 2009
Posts: 328

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: 18896
    
  40

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)
 
 
subject: HashMap