Java中的List是一种存放有序的、可以重复的数据的集合,它允许重复元素的存在。List中的元素都有对应的一个序列号(索引)记录着元素的位置,因此可以通过这个序列号来访问元素。
Java中的List有三种实现方式:ArrayList、LinkedList和Vector。其中,ArrayList是基于数组实现的,LinkedList是基于链表实现的,Vector是基于数组实现的线程安全版本。


ArrayList是基于数组实现的,其中elementData数据存储数据元素,size代表集合大小
/**
* The array buffer into which the elements of the ArrayList are stored.
* The capacity of the ArrayList is the length of this array buffer. Any
* empty ArrayList with elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA
* will be expanded to DEFAULT_CAPACITY when the first element is added.
*/
transient Object[] elementData; // non-private to simplify nested class access
/**
* The size of the ArrayList (the number of elements it contains).
*
* @serial
*/
private int size;
ArrayList的扩容方法是grow(),它会获取到ArrayList中elementData数组的内存空间长度,然后扩容至原来的1.5倍。最后调用Arrays.copyOf方法将elementData数组指向新的内存空间时newCapacity的连续空间。
ArrayList不是线程安全的。
线程安全的List有Vetor,CopyOnWriteArrayList