Lisbon
Lisbon

Reputation: 186

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.

Upvotes: 2

Views: 80

Answers (2)

Octavia
Octavia

Reputation: 242

List<String> valuesList = new ArrayList<>(yourmap.values());

https://www.tutorialspoint.com/Java-program-to-convert-the-contents-of-a-Map-to-list

Upvotes: -1

T.K
T.K

Reputation: 464

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());

Upvotes: 5

Related Questions