Skip to content

Instantly share code, notes, and snippets.

@corajr
Created January 26, 2016 22:00
Show Gist options
  • Save corajr/5b579d02483f524db5ec to your computer and use it in GitHub Desktop.
Save corajr/5b579d02483f524db5ec to your computer and use it in GitHub Desktop.
import java.util.*;
class MapDiff {
public static void main(String[] args) {
Map<String, Integer> m1 = new HashMap<String, Integer>();
m1.put("a", 1);
m1.put("b", 2);
m1.put("c", 3);
Map<String, Integer> m2 = new HashMap<String, Integer>();
m2.put("a", 1);
m2.put("b", 3);
m2.put("c", 3);
Set<Map.Entry<String, Integer>> defaultEntries = m1.entrySet();
Set<Map.Entry<String, Integer>> overridenEntries = m2.entrySet();
overridenEntries.removeAll(defaultEntries);
System.out.println(m2);
// "{b=3}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment