I want to filter a java.util.Collection
based on a predicate.
My answer builds on that from Kevin Wong, here as a one-liner using CollectionUtils
from spring and a Java 8 lambda expression.
CollectionUtils.filter(list, p -> ((Person) p).getAge() > 16);
This is as concise and readable as any alternative I have seen (without using aspect-based libraries)
Spring CollectionUtils is available from spring version 4.0.2.RELEASE, and remember you need JDK 1.8 and language level 8+.