Vector的底层与ArrayList类似.都是以动态数组的方式进行对象的存储
Vector与ArrayList的区别在于Vector是线程同步操作安全的
Vector的并发安全保证
看Vector的源码(如下)发现很多对外的方法都用Synchronized关键字进行修饰
所以通过vector进行操作性能并不高,因此慢慢被放弃
public synchronized void addElement(E obj) {
modCount++;
ensureCapacityHelper(elementCount + 1);
elementData[elementCount++] = obj;
}
public synchronized boolean removeElement(Object obj) {
modCount++;
int i = indexOf(obj);
if (i >= 0) {
removeElementAt(i);
return true;
}
return false;
}
public synchronized E get(int index) {
if (index >= elementCount)
throw new ArrayIndexOutOfBoundsException(index);
return elementData(index);
}
如上可知,Vector是线程安全的,但是性能较差,不推荐使用。
在工作中,我们有可能将集合(ArrayList与linkedList)转换为线程安全。
就要用到Collection工具类
集合转换为线程安全的对象



