Predicate in Java11 filters all elements
What did I do wrong?
You seem to be missing the basic De-morgan's laws which states that
!(a || b) == !a && !b
and
!(a && b) == !a || !b
How do I correct it?
So you should change your code to use
Predicate.not(a -> a.equals("dog") || a.equals("horse")); // !(a || b)
which shall be equivalent to your existing code
Predicate<String> cats = a -> !a.equals("dog") && !a.equals("horse");
that can also be looked upon as:
Predicate<String> notDog = a -> !a.equals("dog");
Predicate<String> notHorse = a -> !a.equals("horse");
Predicate<String> cats = notDog.and(notHorse); // !a && !b