fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.stream.*;
  5. import java.lang.*;
  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. List<String> list = Stream.of(
  14. "06|20|1",
  15. "11|20|2",
  16. "11|20|2",
  17. "07|207|6",
  18. "11|207|2",
  19. "07|207|6"
  20. ).collect(Collectors.toList());
  21.  
  22. Map<String, Map<String, String>> map = list.stream()
  23. .map(line -> line.split("\\|"))
  24. .sorted(Comparator.comparingInt(line -> Integer.parseInt(line[2])))
  25. .collect(Collectors.toMap(
  26. line -> line[1],
  27. line -> Map.of(line[0], line[2]),
  28. (low, high) -> high));
  29.  
  30. System.out.println(map);
  31. }
  32. }
Success #stdin #stdout 0.11s 50768KB
stdin
Standard input is empty
stdout
{207={07=6}, 20={11=2}}