Compare two Maps in Scala

前端 未结 4 1749
刺人心
刺人心 2021-02-06 00:49

Is there any pre-defined function that I can use to compare two Maps based on the key and give me the difference? Right now, I iterate Map1 and foreach key, I check if there is

4条回答
  •  鱼传尺愫
    2021-02-06 00:52

    Consider the difference between the maps converted into sets of tuples,

    (m1.toSet diff m2.toSet).toMap
    

提交回复
热议问题