How can you safely modify a collection while iterating through it?

Last Updated :
Discuss
Comments

How can you safely modify a collection while iterating through it?


Using Iterator.remove()

Using List.remove(Object) inside a loop

Using collection.stream().forEach()


Using for-each loop



Share your thoughts in the comments