When a set of initialization, the initial value of a specified set size.

HashMap storage general case we use the above 1W, the default initial table capacity is 16,

The default reHash doubled capacity each, several times reconstructed, affect performance

 

Description: HashMap using HashMap (int initialCapacity) initialization,
Example n: initialCapacity = (the number of elements need to store / load factor) + 1. Note that the load factor (i.e. Loader
factor) 0.75 default, if the initial value is temporarily unable to determine the size, set to 16 (i.e., default value).
Counter-example: HashMap 1024 elements need to be placed, because there is no capacity to set the initial size, with elements increasing capacity
amount seven times forced to expand, resize need to rebuild the hash table, seriously affect performance.

 

Guess you like

Origin www.cnblogs.com/zwq20134/p/11578404.html