????Vector??capacityIncrement????0?????capacityIncrement??С???????????????2?????????ù???????new???Vector????????capacityIncrement???????????????????2????
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);
}
????Vector?????????????
public Vector(int initialCapacity?? int capacityIncrement) {
super();
if (initialCapacity < 0)
throw new IllegalArgumentException("Illegal Capacity: "+
initialCapacity);
this.elementData = new Object[initialCapacity];
this.capacityIncrement = capacityIncrement;
}
public Vector(int initialCapacity) {
this(initialCapacity?? 0);
}
public Vector() {
this(10);
}
????Vector???????
???????????
??????1??public final synchronized void adddElement(Object obj)
??????obj??????????β????obj???????κ?????????????????????????????????в?????????????????????????????????????????????????????????????????
???????磺?????????1????????????v1.addElement(1)?????????????
????Vector v1 = new Vector();
????Integer integer1 = new Integer(1);
????v1.addElement(integer1);
????(2)public final synchronized void setElementAt(Object obj??int index)
??????index??????????ó?obj?????????????????
????(3)public final synchronized void insertElement(Object obj??int index)
??????index?????λ?ò???obj???????????????????????????????