user710818 user710818 - 5 years ago 169
Java Question

How to receive difference of maps in java?

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 Source

How about google guava?:

Maps.difference(map1,map2)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download