102014Sep

HashMap Load Factor and Initial Capacity

Initial Capacity and Load Factor in HashMap are two parameters that affect its performance.

Initial Capacity In HashMap

The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. Default initial capacity is 16.

Load factor In HashMap

The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed (that is, internal data structures are rebuilt) so that the hash table has approximately twice the number of buckets. Default load factor is 0.75.

It means that after storing the 12th (16 * 0.75 = 12) key into the HashMap , internal data structures are rebuilt and its capacity will become 32.