Using method reference to remove elements from a List

Viewed 1136

What's wrong with my code?

I want to remove all the elements starting with A from the List list:

public static void main(String[] args) {

    Predicate<String> TTT = "A"::startsWith;
    List<String> list = new ArrayList<>();

    list.add("Magician");
    list.add("Assistant");
    System.out.println(list); // [Magician, Assistant]

    list.removeIf(TTT);
    System.out.println(list); // expected output: [Magician]

}

However, removeIf doesn't remove anything from the list.

2 Answers
Related