fork(22) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.Arrays.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args)
  9. {
  10. List<Integer> integerList = Arrays.asList(0, 1, 2, 3, 42);
  11.  
  12. // sequential
  13. long howManyOddNumbers = integerList.stream()
  14. .filter(e -> (e%2) == 1).count();
  15.  
  16. System.out.println(howManyOddNumbers); // Output: 2
  17.  
  18. // parallel
  19. long howManyOddNumbersParallel = integerList.parallelStream()
  20. .filter(e -> (e%2) == 1).count();
  21.  
  22. System.out.println(howManyOddNumbersParallel); // Output: 2
  23. }
  24. }
Success #stdin #stdout 0.22s 321856KB
stdin
Standard input is empty
stdout
2
2