Iterator
Walk through a collection and safely remove elements while iterating.
Easy
for (var it = list.iterator(); it.hasNext();) if (it.next() < 0) it.remove(); — or list.removeIf(x -> x < 0).
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.