深入Java集合学习系列:LinkedList的实现原理
?
1. LinkedList概述:/*** * 当前指针位置:this.next * 当前所操作的对象:this.lastReturned */public void remove() {checkForComodification();LinkedList.Entry localEntry = this.lastReturned.next;try {LinkedList.this.remove(this.lastReturned);} catch (NoSuchElementException localNoSuchElementException) {throw new IllegalStateException();}/*** * 当链表的size为0,指针会指向this.header,其他方法(如set方法)将以此判断当前操作对象的状态 */if (this.next == this.lastReturned)this.next = localEntry;elsethis.nextIndex -= 1;/*** * 调用LinkedList.this.remove(E)之后 * 当前操作对象this.lastReturned指向的对象被设置为this.header(原对象为null) * 指针移动到this.lastReturned.next */this.lastReturned = LinkedList.this.header;//修改次数加1this.expectedModCount += 1;}
以上便是笔者对LinkedList的认识,有不足之处请各位看官多多提点,共同学习,共同进步。