我有以下地图:
Map<String,Map<String,Long>> mapOne;
Map<String,Map<String,Long>> mapTwo;
这些地图中的值看起来像这样:
{
BMW = {
SIZE=1,
SPEED=60
},
AUDI = {
SIZE=5,
SPEED=21
},
SEAT= {
SPEED=15
}
}
第二张地图:
{
Suzuki = {
WHEELS_SIZE=2,
DOORS=3
},
AUDI = {
WHEELS_SIZE=5,
DOORS=5
},
SEAT= {
DOORS=4
}
}
我希望合并后的地图是这样的:
{
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
},
}
我想进行合并,并且将重复键的值进行组合。我认为应该像这样:
mapTwo.forEach((k, v) -> mapOne.merge(k, v, ..... ));