First, when the expansion:
Online summary there will be many, but most are summarized incomplete or inaccurate. Most likely to say the value of the following conditions are satisfied me one.
Expansion must meet two conditions:
1, when storing a new value of the current number of elements must have a threshold value greater than or equal
2, when storing new data value currently stored hash collision occurs (position of the current array index key hash value calculated out in terms of value already exists)
Second, let's look at the source code, as follows:
The first is the put () method
|
There the addEntry call () method put () method, which is specific to this approach stored values, whether or not there is determined before the stored-value capacity is needed
|
If capacity is needed, call the expansion method resize ()
|
transfer () in the actual expansion when the original elements of the array into a new array
|
Third, the summary:
Hashmap expansion required to meet two conditions: the current amount of data stored (i.e., size ()) must be greater than equal to a threshold size; whether the current data is added to the hash conflict occurs.
Since the above two conditions, the presence of such things as
(1), the value is stored in the hashmap of time (the default size is 16, the load factor of 0.75, the threshold 12), may reach the last 16 values is full time, and then stored in the first 17 values of the expansion phenomenon will occur, because the first 16 values each occupy a position in the bottom of the array, hash collision does not occur.
(2), of course, also possible to store more value (more than 16 super value, you can save up to 26 value) have not expansion. Principle: Before a collision hash values of all 11, to keep the same position of the array (in this case the number of elements less than the threshold value 12, not expansion), all 15 values back into the dispersion to all remaining array positions 15 (in this case the number of elements not less than the threshold value, but each element is not stored in hash collision occurs, it will not expansion), the first 11 + 15 = 26, so it satisfies the above values into the 27th time two conditions, when will this expansion phenomenon.
Note: jdk version 1.7