I want to filter a java.util.Collection based on a predicate.
java.util.Collection
With Guava:
Collection collection = Lists.newArrayList(1, 2, 3, 4, 5); Iterators.removeIf(collection.iterator(), new Predicate() { @Override public boolean apply(Integer i) { return i % 2 == 0; } }); System.out.println(collection); // Prints 1, 3, 5