this.loadFactor = loadFactor;
this.threshold = tableSizeFor(initialCapacity);
}
public HashMap(Map<? extends K, ? extends V> m) {
this.loadFactor = DEFAULT_LOAD_FACTOR;
putMapEnt
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
ries(m, false);
}
}
HashMap(int initialCapacity, float loadFactor) 构造函数
前两个没什么好讲的,我们直接看第3个 HashMap(int initialCapacity, float loadFactor)
这里的重点就是 int tableSizeFor(int cap)函数。
tableSizeFor(int cap) 函数
tableSizeFor(int cap) 的作用是返回 大于等于cap 且 最接近cap 的2的幂次方的值
static final int MAXIMUM_CAPACITY = 1 << 30;
/**
- Returns a power of two size for the given target capacity.
- 返回 大于等