List 列表
ArrayList
//实现了list ,底层是动态的对象数组
public class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
{
private static final long serialVersionUID = 8683452581122892189L;
/**
* Default initial capacity.
*/
private static final int DEFAULT_CAPACITY = 10;
/**
* Shared empty array instance used for empty instances.
*/
private static final Object[] EMPTY_ELEMENTDATA = {};
/**
* Shared empty array instance used for default sized empty instances. We
* distinguish this from EMPTY_ELEMENTDATA to know how much to inflate when
* first element is added.
*/
private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {};
/**
* 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
LinkedList
//实现了List和Deque双向列表,底层是链表
public class LinkedList<E>
extends AbstractSequentialList<E>
implements List<E>, Deque<E>, Cloneable, java.io.Serializable
ArrayList和LinkedList都实现了List接口 所以是有序的可以重复的集合,但是LinkedList还实现了Deque结构是双向列表(链表式结构).
比如 我们修改插入 ‘2’ 到下标为1的ArrayList,那么 00002地址给了’2’, 那么之前在00002的数值需要存到后一个00003地址,
后面的内存地址都往后移动.
然而,LinkedList他是链表结构,只记住下标就可以了,当你插入一个值(节点)的时候,它的地址是重新分配的和前后内存地址无关的,改变的只是下标而已. 比如我们也插入’2’ 到下标为2的LinkedList里,系统会给它分配一个未使用的地址(假设是0110),那么之前下标2以及之后的数据,内存还是之前的地址,修改的仅仅是下标,所以效率高.