Created
February 15, 2018 12:22
-
-
Save rain0r/2e3ed0dcde4a77db8fe3efc43e38315a to your computer and use it in GitHub Desktop.
This file contains 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.security.SecureRandom; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.function.Predicate; | |
public class IntegerFilter { | |
public static void main(String... args) { | |
IntegerFilter rp = new IntegerFilter(); | |
rp.doWork(); | |
} | |
public void doWork() { | |
List<Integer> randoms = buildList(); | |
randoms.stream().filter(onlyEvens()).forEach( | |
p -> { | |
System.out.println(String.format("%d is even", p)); | |
}); | |
} | |
private Predicate<Integer> onlyEvens() { | |
return result -> result.intValue() % 2 == 0; | |
} | |
private List<Integer> buildList() { | |
SecureRandom rand = new SecureRandom(); | |
List<Integer> randoms = new ArrayList<>(); | |
for (int i = 0; i < 5; i++) { | |
randoms.add(rand.nextInt()); | |
} | |
return randoms; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment