I want to merge 2 Map
s, but when the key is the same, the values should be appended instead of overwritten.
Let's say
Map<String, Set<String>> map1 = new HashMap<>();
Set<String> set1 = new HashSet<>();
set1.add("AB");
set1.add("BC");
map1.put("ABCD",set1);
Map<String, Set<String>> map2 = new HashMap<>();
Set<String> set2 =new HashSet<>();
set2.add("CD");
set2.add("EF");
map2.put("ABCD",set2);
map1.putAll(map2);
So here the key is same.I know putAll will overwrite the values if key is same
But I am looking for an output like
{ABCD=[AB,BC,CD,ED]}
If someone can help me to resolve, will be so thankful.