Comparing two hashmaps for equal values and same key sets?

后端 未结 6 964
北荒
北荒 2020-12-03 02:18

How can I best compare two HashMaps, if I want to find out if none of them contains different keys than the other, and if the values of that keys match each oth

6条回答
  •  庸人自扰
    2020-12-03 02:58

    Make an equals check on the keySet() of both HashMaps.

    NOTE:

    If your Map contains String keys then it is no problem, but if your Map contains objA type keys then you need to make sure that your class objA implements equals().

提交回复
热议问题