fork download
  1. import java.util.List;
  2. import java.util.Random;
  3. import java.util.stream.Collectors;
  4.  
  5. class Ideone {
  6. public static void main (final String[] args) {
  7. List<Integer> randomNumbers = new Random()
  8. .ints(10)
  9. .map(value -> value >= 0 ? value : -value)
  10. .map(value -> value % 100)
  11. .boxed()
  12. .collect(Collectors.toList());
  13. final List<Integer> evens = extractEvens(randomNumbers);
  14.  
  15. System.out.println("Random numbers: " + randomNumbers);
  16. System.out.println("Even numbers: " + evens);
  17. }
  18.  
  19. public static List<Integer> extractEvens(final List<Integer> numbers) {
  20. return numbers.stream()
  21. .filter(value -> value % 2 == 0)
  22. .collect(Collectors.toList());
  23. }
  24. }
Success #stdin #stdout 0.09s 36868KB
stdin
Standard input is empty
stdout
Random numbers: [47, 96, 64, 8, 47, 89, 30, 13, 2, 70]
Even numbers:   [96, 64, 8, 30, 2, 70]