手写基本容器——Vector
基本的结构
源代码是利用数组的方式来进行底层实现的
/**
* The array buffer into which the components of the vector are
* stored. The capacity of the vector is the length of this array buffer,
* and is at least large enough to contain all the vector's elements.
*
* <p>Any array elements following the last element in the Vector are null.
*
* @serial
*/
protected Object[] elementData;
然后再定义一个数组的大小
/**
* The number of valid components in this {@code Vector} object.
* Components {@code elementData[0]} through
* {@code elementData[elementCount-1]} are the actual items.
*
* @serial
*/
protected int elementCount;
剩下的部分就是和arrayList差不多的操作,只不过区别不同的是:他的每个部分都是加入线程的安全,基本的实现同arrayList一样
有兴趣的可以对比一下arrayList和Vector的源代码,大部分就是加入了许多的关键字,思想是差不多的