I have the following maps:
Map<String,Map<String,Long>> mapOne;
Map<String,Map<String,Long>> mapTwo;
The values inside these maps look something like :
{
BMW = {
SIZE=1,
SPEED=60
},
AUDI = {
SIZE=5,
SPEED=21
},
SEAT= {
SPEED=15
}
}
Second map:
{
Suzuki = {
WHEELS_SIZE=2,
DOORS=3
},
AUDI = {
WHEELS_SIZE=5,
DOORS=5
},
SEAT= {
DOORS=4
}
}
I want the map after the merge to be :
{
BMW = {
SIZE=1,
SPEED=60
},
AUDI = {
SIZE=5,
SPEED=21,
WHEELS_SIZE=5,
DOORS=5
},
SEAT= {
SPEED=15,
DOORS=4
},
Suzuki = {
WHEELS_SIZE=2,
DOORS=3
},
}
So I want to do the merge, and combine the values of duplicate keys. I believe it should be something like this:
mapTwo.forEach((k, v) -> mapOne.merge(k, v, ..... ));