List<String> names = new ArrayList<>(List.of("John Doe", "Jack Doe", "John Smith")); List<String> johns = new ArrayList<>(); for (String name: names) { if (name.startsWith("John")) { johns.add(name); } } names.removeAll(johns);