1List<String> names = new ArrayList<>(List.of("John Doe", "Jack Doe", "John Smith"));
2
3List<String> johns = new ArrayList<>();
4for (String name: names) {
5 if (name.startsWith("John")) {
6 johns.add(name);
7 }
8}
9names.removeAll(johns);