lists removing with iterator

Solutions on MaxInterview for lists removing with iterator by the best coders in the world

showing results for - "lists removing with iterator"
Sofia
28 Apr 2019
1List<String> names = new ArrayList<>(List.of("John Doe", "Jack Doe", "John Smith"));
2Iterator<String> it = names.iterator();
3while (it.hasNext()) {
4    String name = it.next();
5    if (name.startsWith("John")) {
6        it.remove();
7    }
8}