How to receive difference of maps in java?

前端 未结 7 927
不知归路
不知归路 2021-02-05 09:36

I have two maps:

Map map1;
Map map2;

I need to receive difference between these maps. Does exist ma

7条回答
  •  隐瞒了意图╮
    2021-02-05 10:09

    Here is a simple snippet you can use instead of massive Guava library:

    public static  Map mapDifference(Map left, Map right) {
        Map difference = new HashMap<>();
        difference.putAll(left);
        difference.putAll(right);
        difference.entrySet().removeAll(right.entrySet());
        return difference;
    }
    

    Check out the whole working example

提交回复
热议问题