基础结构是数组。
extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable
属性:
//元素数组
protected Object[]
elementData
;
//元素数量
protected int
elementCount
;
//承载力增长值,如果为0就按2倍方式增长
protected int
capacityIncrement
;
private static final long
serialVersionUID = -
2767605614048989439L
;
数据结构和变量几乎和ArrayList差不多,不同的是Vector线程安全。
默认承载力为10.
增容主要代码:
private void grow(int minCapacity) {
// overflow-conscious code
int oldCapacity = elementData.length;
int newCapacity = oldCapacity + ((capacityIncrement > 0) ?
capacityIncrement : oldCapacity);
if (newCapacity - minCapacity < 0)
newCapacity = minCapacity;
if (newCapacity - MAX_ARRAY_SIZE > 0)
newCapacity = hugeCapacity(minCapacity);
elementData = Arrays.copyOf(elementData, newCapacity);
}
主要是对外的方法都是
synchronized修饰,来实现线程同步安全。