访问 class 遍历 pre 元素 www tro col
Vector 简介
Vector 是矢量队列,它是 JDK1.0 版本添加的类。继承于 AbstractList,实现了 List, RandomAccess, Cloneable 这些接口。Vector 继承了 AbstractList,实现了 List;所以,它是一个队列,支持相关的添加、删除、修改、遍历等功能。Vector 实现了 RandmoAccess 接口,即提供了随机访问功能。RandmoAccess 是 java 中用来被 List 实现,为 List 提供快速访问功能的。在 Vector 中,我们即可以通过元素的序号快速获取元素对象;这就是快速随机访问。Vector 实现了 Cloneable 接口,即实现 clone() 函数。它能被克隆。和 ArrayList 不同,Vector 中的操作是线程安全的。
Vector 的源码分析
Vector 源码和 ArrAyList 基本一致, 。如需 ArrAyList 源码分析,详情请见 http://www.cnblogs.com/scholar-xie/p/7000082.html
差异区别
- /**
- * synchronized*/
- public synchronized void addElement(E obj) {
- modCount++;
- ensureCapacityHelper(elementCount + 1);
- elementData[elementCount++] = obj;
- }
- /**
- * synchronized */
- public synchronized void removeAllElements() {
- modCount++;
- // Let gc do its work
- for(inti = 0; i < elementCount; i++)
- elementData[i] =null;
- elementCount = 0;
- }
- /**
- * 方法上面加上了 synchronized*/
- public synchronizedE get(int index) {
- if(index >= elementCount)
- throw new ArrayIndexOutOfBoundsException(index);
- return elementData(index);
- }
Vector 源码分析 jdk1.8
来源: http://www.bubuko.com/infodetail-2117589.html