Use Iterator#remove
.
This is the only safe way to modify a collection during iteration. For more information, see The Collection Interface tutorial.
If you also need the ability to add elements while iterating, use a ListIterator
.
Use Iterator#remove
.
This is the only safe way to modify a collection during iteration. For more information, see The Collection Interface tutorial.
If you also need the ability to add elements while iterating, use a ListIterator
.