Created
February 20, 2018 11:34
-
-
Save rain0r/ea292485ff29e49d2037aa3ffe349941 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