Created
January 26, 2016 22:00
-
-
Save corajr/5b579d02483f524db5ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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