1.选择的特征:
LinkedList:插入与删除操作多,当成队列使用
ArrayList:
可以切片–> subList(int fromIndex, int toIndex) ,清除不需要的元素–> retainAll(Collection<?> c)
2.内部容器
ArrayList:
private transient Object[] elementData;
LinkedList:
private static class Node<E> {
E item;
Node<E> next; // 指向下一个节点
Node<E> prev; //指向上一个节点
Node(Node<E> prev, E element, Node<E> next) {
this.item = element;
this.next = next;
this.prev = prev;
}
}
3.共同方法
略
4.LinkedList特有的方法
队列操作:peek() //不移除 poll() //移除 pop() push()
descendingIterator() //逆向排序
removeFirstOccurrence(Object o)
removeLastOccurrence(Object o)
5.ArrayList特有的方法
isEmpty()
removeRange(int fromIndex, int toIndex)
retainAll(Collection<?> c)
subList(int fromIndex, int toIndex)
trimToSize() //初始申请容量10,结果只使用了5,那么trimToSize()之后ArrayList的容量就是5.