fork download
  1. import java.util.*;
  2. import static java.util.stream.Collectors.*;
  3. class Ideone {
  4. public static void main (String[] args) {
  5. List<Map<String, List<String>>> list =new ArrayList();
  6. Map<String, List<String>> map1 =new HashMap();
  7. List<String> values =new ArrayList();
  8. values.add("TEST");
  9. values.add("TEST1");
  10. map1.put("level",values);
  11. Map<String, List<String>> map2 =new HashMap();
  12. List<String> values2 =new ArrayList();
  13. values2.add("TEST2");
  14. values2.add("TEST3");
  15. map2.put("level",values2);
  16. list.add(map1);
  17. list.add(map2);
  18.  
  19. List<String> allValues = list.stream() // a stream of Maps
  20. .map(Map::values) // a stream of Collection<List<String>>
  21. .flatMap(Collection::stream) // a stream of List<String>
  22. .flatMap(List::stream) // a stream of String
  23. .collect(toList());
  24.  
  25. System.out.println(allValues);
  26. } }
  27.  
Success #stdin #stdout 0.1s 40340KB
stdin
Standard input is empty
stdout
[TEST, TEST1, TEST2, TEST3]