Home > Back-end >  Capacity of a HashMap what mean? The bosses genuflect is begged
Capacity of a HashMap what mean? The bosses genuflect is begged

Time:12-23

HashMap the default capacity is 16 load factor is 0.75, the 16 refers to the capacity or the underlying array to add the number of elements, if is to point to add the number of elements in the capacity of the underlying array is how to determine? Specific is when to start expanding, is added to the 12 elements began expanding or array expansion and capacity to 0.75?

CodePudding user response:

refer to the original poster AttackCityLion_ response:
HashMap the default capacity is 16 load factor is 0.75, the 16 refers to the capacity or the underlying array to add the number of elements, if is to point to add the number of elements in the capacity of the underlying array is how to determine? Specific is when to start expanding, is added to the 12 elements began expanding or array expansion and capacity to 0.75?


The default capacity is the maximum capacity, 16 is the base, with each capacity increase capacity, capacity is the size, the maximum capacity is maxsize, when the size/maxsize is greater than or equal to 0.75 began to increase,

CodePudding user response:

This refers to the capacity of the underlying array of 16, not the number of elements, if it is really the number of elements, the HashMap will frequently expansion

CodePudding user response:

refer to the original poster AttackCityLion_ response:
HashMap the default capacity is 16 load factor is 0.75, the 16 refers to the capacity or the underlying array to add the number of elements, if is to point to add the number of elements in the capacity of the underlying array is how to determine? Specific is when to start expanding, is added to the 12 elements began expanding or array expansion and capacity to 0.75?


Is a container maximum storage capacity, such as a 500 ml glass of water, the capacity is 500 ml, hashmap capacity is based on DEFAULT_INITIAL_CAPACITY MAXIMUM_CAPACITY determines the two, that is to say, a hashmap is not infinite, there is a maximum,
When can increase by viewing the source code to solve, and put a elements, would need to determine whether capacity, if you need capacity, a capacity increases, so it's not 16 * 0.75=12 expansion, for the first time, it's time to put a 13 elements, trigger the expansion of the
+ + modCount;
If (+ + size & gt; Threshold)
The resize ();//put the final stages of expansion and determine whether 13 & gt; Therefore increase 12==12 no expansion
AfterNodeInsertion (evict);
return null;
  • Related