ArrayList:是数组数据结构,扩容是通过扩容数组。可快速访问其中一个元素或修改。
ListedList:是链表数据结构,可高效的实现中间元素修改/删除。但是访问没有数组高效。
vector:是强同步的ArrayList
ArrayList扩容步骤
1.判断申请的元素后,元素数量超过现有容量。
private void ensureExplicitCapacity(int minCapacity) {
modCount++;
// overflow-conscious code
if (minCapacity - elementData.length > 0)
grow(minCapacity);
}
2.申请1.5倍(一开始是10个元素)空间。
private void grow(int minCapacity) {
// overflow-conscious code
int oldCapacity = elementData.length;
int newCapacity = oldCapacity + (oldCapacity >> 1);
if (newCapacity - minCapacity < 0)
newCapacity = minCapacity;
if (newCapacity - MAX_ARRAY_SIZE > 0)
newCapacity = hugeCapacity(minCapacity);
// minCapacity is usually close to size, so this is a win:
elementData = Arrays.copyOf(elementData, newCapacity);
}
3.拷贝数据到新的数组中
标签:Vector,int,ArrayList,elementData,ListedList,newCapacity,minCapacity From: https://www.cnblogs.com/jichenghui/p/18359052