Java collections XMind and notes

Java in a few precautions when using collections:

1.ArrayList HashMap and has expansion

ArrayList initialize the array length is 10, the original capacity after expansion of 1.5 times.

HashMap length of the array 16 is initialized, control the amount of expansion after 2 times the original.

Why supplement HashMap expansion is 2 times the original?

16, 32, 64 ......
15, 31, 63 ......

like 15,31,63 binary values of these last few bits are all 1.
If the last few bits are all 1, then so is the number of hash values can be obtained
(the array each index position may be considered, or else there must be some index positions will never be able to get, that is, will never be able to store data)

1111
0000
-----
1111

1111
0100
----
0100

1111
the X-
----
the X-

If the problem is not 1111
1011
0100
----
0000

1011
0111
----
0011 Note: so there will be some value can never be

 

Guess you like

Origin www.cnblogs.com/atBruce/p/12109122.html