private class Itr implements Iterator<E> { int cursor; // index of next element to return 当前位置 int lastRet = -1; // index of last element returned; -1 if no such 上一个位置 int expectedModCount = modCount; // 期待的ModeCount,控制并发修改
@SuppressWarnings("unchecked") public E next() { checkForComodification(); int i = cursor; if (i >= size) throw new NoSuchElementException(); Object[] elementData = ArrayList.this.elementData; if (i >= elementData.length) throw new ConcurrentModificationException(); cursor = i + 1; return (E) elementData[lastRet = i]; }
public void remove() { if (lastRet < 0) throw new IllegalStateException(); checkForComodification();