Iterator in Java — a practical guide to Java Iterator with clear examples you can reuse in real projects.
Java Tutorial Series (57/90). Prefer one article? Read the complete Java tutorial.
Short description
Use Iterator when you need to remove elements during traversal.
Iterator remove
import java.util.*;
List<String> list = new ArrayList<>(List.of("a", "b", "c"));
Iterator<String> it = list.iterator();
while (it.hasNext()) {
if (it.next().equals("b")) it.remove();
}