Is there a more elegant way in Guava to remove items which meet a certain predicate from a collection and collect these removed items at the same time? See code below for an example.
public static void main(String[] a) { final List<String> list = new LinkedList<String>(); list.add("..."); ... final List<String> removedItems = new LinkedList<String>(); Iterables.removeIf(list, new Predicate<String>() { public boolean apply(final String o) { if (...) { // some condition removedItems.add(o); return true; } return false; } }); System.out.println(removedItems); } Thanks!
edit: My question is not about partitioning a list, but about removing elements from a collection and collecting them at the same time. I edited my question to avoid confusion.