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