I want to filter a java.util.Collection
based on a predicate.
The simple pre-Java8 solution:
ArrayList- filtered = new ArrayList
- ();
for (Item item : items) if (condition(item)) filtered.add(item);
Unfortunately this solution isn't fully generic, outputting a list rather than the type of the given collection. Also, bringing in libraries or writing functions that wrap this code seems like overkill to me unless the condition is complex, but then you can write a function for the condition.