java - What is the significance of load factor in HashMap? -


hashmap has 2 important properties: size , load factor. went through java documentation , says 0.75f initial load factor. can't find actual use of it. can describe different scenarios need set load factor , sample ideal values different cases?

the documentation explains pretty well:

an instance of hashmap has 2 parameters affect performance: initial capacity , load factor. capacity number of buckets in hash table, , initial capacity capacity @ time hash table created. load factor measure of how full hash table allowed before capacity automatically increased. when number of entries in hash table exceeds product of load factor , current capacity, hash table rehashed (that is, internal data structures rebuilt) hash table has approximately twice number of buckets.

as general rule, default load factor (.75) offers tradeoff between time , space costs. higher values decrease space overhead increase lookup cost (reflected in of operations of hashmap class, including , put). expected number of entries in map , load factor should taken account when setting initial capacity, minimize number of rehash operations. if initial capacity greater maximum number of entries divided load factor, no rehash operations ever occur.

as performance optimizations, idea avoid optimizing things prematurely (i.e. without hard data on bottlenecks are).


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -