How to merge two maps into one with keys from the first map and merged values?

前端 未结 3 891
暗喜
暗喜 2021-01-14 07:10

How can I create a new map from two maps of maps so that the resulting map only includes matches where keys are the same and combines the internal maps.

Iter         


        
3条回答
  •  情话喂你
    2021-01-14 07:45

    val keys = map1.keySet & map2.keySet
    val map3 = keys.map(k => k -> (map1(k) ++ map2(k)))
    

提交回复
热议问题