Skip to content

Instantly share code, notes, and snippets.

@csamuel
Created February 9, 2011 05:29
Show Gist options
  • Save csamuel/817936 to your computer and use it in GitHub Desktop.
Save csamuel/817936 to your computer and use it in GitHub Desktop.
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
public class GuavaEvensFilter {
public static void main (String [] args)
{
// Prints "[2, 4]"
System.out.println(
Iterables.filter(
Lists.newArrayList(1, 2, 3, 4),
new Predicate<Integer>() {
public boolean apply(Integer x) {
return x % 2 == 0;
}
})
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment