Search code examples
javacollectionsjava-stream

How to convert List<Map<String, String>> into the list containing the values of the map in Java 8


Given: a List<Map<String,String>>.

I want to get List<String> of values of the map.


Solution

  • If I understand correctly what you mean you can do something like this :

    List<Map<String, String>> listOfMaps = ...;
    List<String> values = listOfMaps.stream()
        .flatMap(map -> map.values().stream())
        .collect(Collectors.toList());