Answers for "Lists - removing with iterator"

0

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();
    }
}
Posted by: Guest on April-25-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language