Add two maps in Groovy while summing up values for common keys

前端 未结 7 933
花落未央
花落未央 2020-12-16 12:24

I have two maps in Groovy [a: 1, b: 2] and [b:1, c:3] and would like to create from them a third map [a: 1, b: 3, c: 3]. Is there a Gr

7条回答
  •  情书的邮戳
    2020-12-16 12:46

    The following example demonstrates adding two maps, to a third map m3:

    Map m1 = [ a:1, b:2 ];
    Map m2 = [ b:1, c:3 ];
    Map m3 = [:];
    m3 << m1
    m3 << m2
    

提交回复
热议问题