Created
September 21, 2018 06:44
-
-
Save Cvetomird91/a7cbd75188d92912a43d45d622d92a1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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