private class LinkedListIterator implements Iterator<AnyType>{
private Node<AnyType> current = beginMarker.next;
private int expectedModCount = modCount;
private boolean okToMove = false;
@Override
public boolean hasNext() {
return current!=endMarker;
}
@Override
public AnyType next() {
if(modCount != expectedModCount){
throw new ConcurrentModificationException();
}
if(!hasNext()){
throw new NoSuchElementException();
}
AnyType nextItem = current.data;
current = current.next;
okToMove = true;
return nextItem;
}
@Override
public void remove() {
if(modCount != expectedModCount){
throw new ConcurrentModificationException();
}
if(!okToMove){ //防止连续调用remove方法
throw new IllegalStateException();
}
MyLinkedList.this.remove(current.pre);
expectedModCount--;
}
} private class LinkedListIterator implements