fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.function.*;
  5. import java.util.stream.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Stream<String> lines = Stream.of("item1,16,2",
  14. "item2,17,3",
  15. "item1,16,5");
  16. Map<String, List<Integer>> map =
  17. lines.map(s -> s.split(","))
  18. .collect(Collectors.toMap(a -> a[0],
  19. a -> Arrays.asList(a).stream()
  20. .skip(1).map(Integer::parseInt)
  21. .collect(Collectors.toList()),
  22. (a, b) -> {for (int i = 0; i < a.size(); i++) a.set(i, a.get(i) + b.get(i)); return a;}));
  23. System.out.println( map);
  24.  
  25. }
  26. }
Success #stdin #stdout 0.2s 320576KB
stdin
Standard input is empty
stdout
{item2=[17, 3], item1=[32, 7]}