how to remove from a list using a iterator code example
Example: Lists - removing with iterator
List<String> names = new ArrayList<>(List.of("John Doe", "Jack Doe", "John Smith"));
Iterator<String> it = names.iterator();
while (it.hasNext()) {
String name = it.next();
if (name.startsWith("John")) {
it.remove();
}
}