我看为什么没有找到关于乘2加2的内容
private int newCapacity(int minCapacity) {
int oldLength = value.length;
int newLength = minCapacity << coder;
int growth = newLength - oldLength;
int length = ArraysSupport.newLength(oldLength, growth, oldLength + (2 << coder));
if (length == Integer.MAX_VALUE) {
throw new OutOfMemoryError("Required length exceeds implementation limit");
}
return length >> coder;
}
实现的方式不一样了而已。
int length = ArraysSupport.newLength(oldLength, growth, oldLength + (2 << coder));
ArraysSupport.newLength这里就是比较growth和oldLength + (2 << coder)谁大,大者加上oldLength(这样就成了2倍+2)