Skip to content

Instantly share code, notes, and snippets.

@Cvetomird91
Created September 21, 2018 06:44
Show Gist options
  • Save Cvetomird91/a7cbd75188d92912a43d45d622d92a1f to your computer and use it in GitHub Desktop.
Save Cvetomird91/a7cbd75188d92912a43d45d622d92a1f to your computer and use it in GitHub Desktop.
import java.util.*;
import java.util.function.*;
public class PredicateSearch {
public static void main(String[] args) {
List<Animal> animals = new ArrayList<Animal>();
animals.add(new Animal("fish", false, true));
animals.add(new Animal("shark", false, true));
animals.add(new Animal("monkey", true, false));
animals.add(new Animal("bunny", true, false));
print(animals, a -> a.canHop());
print(animals, a -> a.canSwim());
}
private static void print(List<Animal> animals, Predicate<Animal> checker) {
for (Animal animal : animals) {
if (checker.test(animal))
System.out.println(animal + " ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment