您必须使用和
Iterator来迭代
remove迭代器(而不是列表)的功能:
Iterator<Pulse> iter = pulseArray.iterator();while (iter.hasNext()) { Pulse p = iter.next(); if (p.getCurrent()==null) iter.remove();}注意,迭代器#删除功能被认为是optionnal,但它
是 由ArrayList的迭代器来实现。
这是ArrayList.java中此具体功能的代码:
765 public void remove() {766 if (lastRet < 0)767 throw new IllegalStateException();768 checkForComodification();769 770 try {771 ArrayList.this.remove(lastRet);772 cursor = lastRet;773 lastRet = -1;774 expectedModCount = modCount;775 } catch (IndexOutOfBoundsException ex) {776 throw new ConcurrentModificationException();777 }778 }779 780 final void checkForComodification() {781 if (modCount != expectedModCount)782 throw new ConcurrentModificationException();783 }784 }这
expectedModCount = modCount;行代码就是为什么在迭代时使用它时不会抛出异常。



