I would like to merge two Map with JAVA 8 Stream:
Map> mapGlobal = new HashMap>();
Map
Using StreamEx
Map> mergedMap =
EntryStream.of(mapGlobal)
.append(EntryStream.of(mapAdded))
.toMap((v1, v2) -> {
List combined = new ArrayList<>();
combined.addAll(v1);
combined.addAll(v2);
return combined;
});
If you have even more maps to merge just append to the stream
.append(EntryStream.of(mapAdded2))
.append(EntryStream.of(mapAdded3))