Your compilation error is due to the fact that you're passing an Iterator
to Iterables.filter
, which expects an Iterable
as its first argument. You want Iterators.filter
.
It's unrelated to your actual problem, but since you asked: Iterables.filter
takes a Predicate<? super T>
so that you can, for example, use a Predicate<Object>
to filter a List<String>
. If the predicate can handle some supertype of the type you want to filter, you can use that predicate.