Iterator (von ArrayList) in while-schleife

Hi,

Ich habe eine ArrayList, über die ich mit einem Iterator eine while-schleife laufen lasse (while (i.hasNext())).
In der schleife frage ich dann den wert ab:
hm = (HashMap)i.next();
und prüfe dann nach best. Kriterien, ob der Eintrag in der ArrayList bleiben soll. Wenn das nicht der Fall ist, wird er rausgeworfen:
resultList.remove(meincounter);
Beim nächsten iteratorzugriff fliegt mir dann die While-schleife um die ohren.

mir scheint, der iterator kommt damit nicht klar, das plötzlich keine Daten mehr da sind, wo eigentlich welche sein sollten…
Aber eine Lösung habe ich nicht.

Kann mir jemand eine anbieten?

Jan

Hallo,
i.remove() heißt eine Lsg.

Gruss
Enno

Danke (oT)
Danke, das war’s.

Hallo,
i.remove() heißt eine Lsg.

Gruss
Enno

Hallo, hier noch die Erklärung aus der javadoc:

The iterators returned by this class’s iterator and listIterator methods are fail-fast: if list is structurally modified at any time after the iterator is created, in any way except through the iterator’s own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

Grüße
Bruno