Удалить элементы из коллекции во время итерации
AFAIK, есть два подхода:
Iterate over a copy of the collection Use the iterator of the actual collectionНапример,
<code>List<Foo> fooListCopy = new ArrayList<Foo>(fooList); for(Foo foo : fooListCopy){ // modify actual fooList } </code>
а также
<code>Iterator<Foo> itr = fooList.iterator(); while(itr.hasNext()){ // modify actual fooList using itr.remove() } </code>
Есть ли причины предпочитать один подход другому (например, предпочтение первого подхода по простой причине читабельности)?