Get inner most values in the Map as a List in `Map<String, List<Map<String,Map<String,String>>>>` Java

RAm Prasad :

I need to get the values in the inner most map as a list in Map<String, List<Map<String,Map<String,String>>>>.

Other than for each, Can we implement it using streams?

dan1st :

Stream#flatMap returns a Stream of all values of all elements:

List<String> converted = yourComplexStructure.values().stream()
    .flatMap(List::stream)
    .map(Map::values)
    .flatMap(Collection::stream())
    .map(Map::values)
    .flatMap(Collection::stream()))
    .collect(Collectors.toList());

It takes the values of your structure as a Stream, maps it to a Stream with all elements of each List, maps it to a Stream with all values of the Maps, creates a Stream with all values of the most inner maps and collects it.


Note that it is basically the same as the other answer (we wrote it at the same time) but I changed this answer so that it doesn't require lambdas but uses method references.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

convert map string string to map string list string - Java 7

Java 8 List<Foo> to Map<String, Map<String, List<String>>>

Comparing a List<Map<String, String>> to a List<Map<String, Object>> Java

Convert List<String> to Map<String, String> in Java

Java Convert List<String> to Map<String, String>

Java8: Transform Map<String,List<String>> into Map<String,String> by joining the values

How to convert a list of java objects to Map<String, Map<String, String>>

How to add Map<String, string> into Map<String, List<Object>> in java

Reduce map(map(map(list(string)))) terraform

How to Convert a List Into Map of Map Map<String, Map<String,Object>>

Java List<String> to Map<String, Integer> convertion

How to junit List<Map<String, String>> in java?

List<Map<String, String>> alternatives (Java)

List<Map<String, String>> vs List<? extends Map<String, String>>

how to convert List<Map<String, String>> to Map<String, List<String>>

Convert Map<String,List<String>> to List<Map<String,String>> in Kotlin

Convert String to List of Map

Create a map of string to List

List of String to Map

Map string to list racket

Map<String,List<String>> to Pair<String,String>

sorting a List of Map<String, String>

Sort a List of Map<String, String>

Converting List<Map<String, List<String>>> to String[][]

Map<String, Map<String, Car>> to List<Car> using Java 8

Convert List<Map<String, Object>> to Map<String, List<Map<String, Object>>> using Java 8 streams API

How to group List<Map<String,Object>> to Map<String,List<Map<String,Object>> in Java8

Java 8: How to convert List<String> to Map<String,List<String>>?

Java 8 List of Objects to Map<String, List> of values