fork 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<Map<String,List<String>>> list=new ArrayList<>();
  14. Map<String,List<String>> map1=new HashMap<>();
  15. map1.put("1", Arrays.asList(new String[] {"A"}));
  16. map1.put("2", Arrays.asList(new String[] {"B"}));
  17.  
  18. Map<String,List<String>> map2=new HashMap<>();
  19. map2.put("1", Arrays.asList(new String[] {"C"}));
  20. map2.put("2", Arrays.asList(new String[] {"D"}));
  21. list.add(map1);
  22. list.add(map2);
  23.  
  24. Map<String, List<String>> result = new HashMap<>();
  25. result.put("1", list.stream()
  26. .filter(e -> e.containsKey("1"))
  27. .flatMap(e -> e.values().stream())
  28. .flatMap(List::stream)
  29. .collect(Collectors.toList()));
  30. Map<String, List<String>> result2 = list.stream()
  31. .filter(e -> e.containsKey("1"))
  32. .flatMap(e -> e.values().stream())
  33. .flatMap(List::stream)
  34. .collect(Collectors.groupingBy(t -> "1"));
  35.  
  36. System.out.println(result.equals(result2));
  37. }
  38.  
  39. }
Success #stdin #stdout 0.13s 34520KB
stdin
Standard input is empty
stdout
true