I want to filter a java.util.Collection
based on a predicate.
Since the early release of Java 8, you could try something like:
Collection collection = ...;
Stream stream = collection.stream().filter(...);
For example, if you had a list of integers and you wanted to filter the numbers that are > 10 and then print out those numbers to the console, you could do something like:
List numbers = Arrays.asList(12, 74, 5, 8, 16);
numbers.stream().filter(n -> n > 10).forEach(System.out::println);