Answers for "iterator remove from list"

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
0

remove items from list while iterating python

somelist = [x for x in somelist if not determine(x)]
Posted by: Guest on February-04-2022

Browse Popular Code Answers by Language