fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.concurrent.atomic.*;
  7. import java.util.stream.*;
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone{
  10. public static void main (String[] args) throws java.lang.Exception{
  11. AtomicInteger counter = new AtomicInteger(0);
  12. Integer[] array = {4, 2, 3, 4, 1, 1, 1, 2, 1};
  13.  
  14. Arrays.asList(array).stream()
  15. .collect(Collectors.groupingBy(it -> counter .getAndIncrement() / 3))
  16. .values().stream()
  17. .mapToInt(val-> val.stream().mapToInt(Integer::intValue).sum())
  18. .forEach(System.out::print);
  19. }
  20. }
Success #stdin #stdout 0.2s 34172KB
stdin
Standard input is empty
stdout
964