How to receive difference of maps in java?

user710818 picture user710818 · Oct 4, 2012 · Viewed 27.2k times · Source

I have two maps:

Map<String, Object> map1;
Map<String, Object> map2;

I need to receive difference between these maps. Does exist may be apache utils how to receive this difference? For now seems need take entry set of each map and found diff1 = set1 - set2 and diff2 = set2- set1. After create summary map =diff1 + diff2 It looks very awkwardly. Does exist another way? Thanks.

Answer

Koerr picture Koerr · Oct 4, 2012

How about google guava?:

Maps.difference(map1,map2)