几个核心的成员变量
1 | static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16 |
初始化桶的大小,因为底层为数组,所以这是数组的默认大小为16
1 | static final int MAXIMUM_CAPACITY = 1 << 30; |
桶的最大值为$2^{30}$
1 | static final float DEFAULT_LOAD_FACTOR = 0.75f; |
默认的负载因子为0.75
1 | transient int size; |
Map中key-value的个数
1 | int threshold; |
扩容的临界值,当实际K-V个数超过threshold时,HashMap会将数组长度扩容,threshold=capacity*loadFactor
1 | final float loadFactor; |
负载因子