CS-Notes
CS-Notes copied to clipboard
Java 容器 JDK.1.7 HashMap 扩容源代码描述
Background:
https://github.com/CyC2018/CS-Notes/blob/master/notes/Java%20%E5%AE%B9%E5%99%A8.md#5-%E6%89%A9%E5%AE%B9-%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86
loadFactor | 装载因子,table 能够使用的比例,
threshold = capacity * loadFactor。
Suggest change
loadFactor | 装载因子,table 能够使用的比例,threshold = (int)(newCapacity * loadFactor)。
Cause
Jdk 1.7 HashMap source code
final float loadFactor;
int threshold;
void resize(int newCapacity) {
// do something()
threshold = (int)(newCapacity * loadFactor);
}
@ruiHut ok