标签:容量 源码 final obj int city object ini 数据
ArrayList
LinkedList
Vector
transient Object[] elementData;
/**
* Default initial capacity.
*/
private static final int DEFAULT_CAPACITY = 10;
private void grow(int minCapacity) {
// 获得原来数组的长度
int oldCapacity = elementData.length;
// oldCapacity >> 1 相当于除以2,新容量是原来容量的1.5倍
int newCapacity = oldCapacity + (oldCapacity >> 1);
if (newCapacity - minCapacity < 0)
newCapacity = minCapacity;
if (newCapacity - MAX_ARRAY_SIZE > 0)
newCapacity = hugeCapacity(minCapacity);
// 把旧数据数据复制到新数组中,替换原来数组
elementData = Arrays.copyOf(elementData, newCapacity);
}
标签:容量 源码 final obj int city object ini 数据
原文地址:https://www.cnblogs.com/macht/p/11923121.html