Skip to content
Advertisement

Create a merged map with list of maps

I’m new to java so seeking help from experts. any help would be much appreciated, and a scope for me to learn new things.

I want to create a List of maps(resultList) from a another list of maps(list) where a single map(keys) contains values which are keys to the list of maps(map1, map2, map3 … So on). Like below example

JavaScript

Now I want values of first map(keys) as key to each new map(mergedMap) for the values of second map(map1) and third map(map2) and so on.

Required output should be like

JavaScript

Advertisement

Answer

Another way to do it using streams.

JavaScript

Note: The filter checks if the value is present in the map before creating the map.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement