I have a HashMap which in turn has a HashMap within,
Map<Long, Map<String, Double>> map = new HashMap<>();
I will have multiple inner maps for the same Long
value, how do I make sure that the value field isn't replaced and rather merged (appended)?
This question differs from How to putAll on Java hashMap contents of one to another, but not replace existing keys and values? as it is about a Map of Strings, I'm stuck with a map of maps
For instance
Map<Long, Map<String, Double>> map = new HashMap<>();
Map<String, Double> map1 = new HashMap<>();
Map<String, Double> map2 = new HashMap<>();
map1.put("1key1", 1.0);
map1.put("1key2", 2.0);
map1.put("1key3", 3.0);
map2.put("2key1", 4.0);
map2.put("2key2", 5.0);
map2.put("2key3", 6.0);
map.put(222l, map1);
map.put(222l, map2);
should give me 6 innermap entries for key '222' and not 3.