标签:size item on() private move except 线程 集合类 rem
transient int size = 0;
transient Node<E> first; // 指向第一个元素
transient Node<E> last; // 指向最后一个元素
链表结点,三个属性:元素、上一结点、下一结点
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; } }
public boolean add(E e) { linkLast(e); return true; } void linkLast(E e) { final Node<E> lastTmp = last; final Node<E> newNode = new Node<>(lastTmp, e, null); last = newNode; if (lastTmp == null) first = newNode; else lastTmp.next = newNode; size++; modCount++; }
public E removeLast() { final Node<E> l = last; if (l == null) throw new NoSuchElementException(); return unlinkLast(l); } private E unlinkLast(Node<E> l) { // assert l == last && l != null; final E element = l.item; final Node<E> prev = l.prev; l.item = null; l.prev = null; // help GC last = prev; if (prev == null) first = null; else prev.next = null; size--; modCount++; return element; }
向后增加新结点
http://blog.csdn.net/ns_code/article/details/35787253
标签:size item on() private move except 线程 集合类 rem
原文地址:http://www.cnblogs.com/zj90/p/7653503.html