Answers for "Lists - removing"

0

Lists - removing

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

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language