I have a nested HashMap
in this form:
{key1=val1, key2=val2,
key3=[
{key4=val4, key5=val5},
{key6=val6, key7=val7}
]
}
I now want to flatten that map, so that all entries are on the same level:
{key1=val1, key2=val2, key4=val4, key5=val5,key6=val6, key7=val7}
When I try
map.values().forEach(map.get("key3")::addAll);
as described in this post, I get the following error:
invalid method reference
cannot find symbol
symbol: method addAll(T)
location: class Object
where T is a type-variable:
T extends Object declared in interface Iterable
Is there any generic way to flatten any given Map
?
instanceOf
check againstMap
, I assumemap.get("key3")::addAll
makes no sense since you seem to have aMap<String, Object>
.Map
where the code that you've shared works.Map
? It can't beMap<String, String>
if some of the entries areEntry<String, Map<String, String>>
. You need to include the code for us to understand what you actually have.