Iterator删除元素的确切方式取决于其实现,这对于不同的Collection可能有所不同。绝对不会中断您所处的循环。我只是看了如何实现ArrayList迭代器,下面是代码:
public void remove() { if (lastRet < 0) throw new IllegalStateException(); checkForComodification(); try { ArrayList.this.remove(lastRet); cursor = lastRet; lastRet = -1; expectedModCount = modCount; } catch (IndexOutOfBoundsException ex) { throw new ConcurrentModificationException(); }}因此,它检查并发修改,使用公共ArrayList remove
方法删除元素,并递增列表修改的计数器,以便在下一次迭代时不会引发ConcurrentModificationException。



