import java.util.HashMap;
import java.util.Map;
class Ideone {
public static <K, V> Map<K, V> mapDifference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right) {
Map<K, V> difference = new HashMap<>();
difference.putAll(left);
difference.putAll(right);
difference.entrySet().removeAll(right.entrySet());
return difference;
}
public static void main
(String[] args
) { Map
<String, String
> map1
= new HashMap
<>(); Map
<String, String
> map2
= new HashMap
<>();
map1.put("a", "1");
map1.put("b", "2");
map2.put("b", "2");
map2.put("d", "4");
System.
out.
println(mapDifference
(map2, map1
)); }
}
aW1wb3J0IGphdmEudXRpbC5IYXNoTWFwOwppbXBvcnQgamF2YS51dGlsLk1hcDsKCmNsYXNzIElkZW9uZSB7CiAgICBwdWJsaWMgc3RhdGljIDxLLCBWPiBNYXA8SywgVj4gbWFwRGlmZmVyZW5jZShNYXA8PyBleHRlbmRzIEssID8gZXh0ZW5kcyBWPiBsZWZ0LCBNYXA8PyBleHRlbmRzIEssID8gZXh0ZW5kcyBWPiByaWdodCkgewogICAgICAgIE1hcDxLLCBWPiBkaWZmZXJlbmNlID0gbmV3IEhhc2hNYXA8PigpOwogICAgICAgIGRpZmZlcmVuY2UucHV0QWxsKGxlZnQpOwogICAgICAgIGRpZmZlcmVuY2UucHV0QWxsKHJpZ2h0KTsKICAgICAgICBkaWZmZXJlbmNlLmVudHJ5U2V0KCkucmVtb3ZlQWxsKHJpZ2h0LmVudHJ5U2V0KCkpOwogICAgICAgIHJldHVybiBkaWZmZXJlbmNlOwogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBNYXA8U3RyaW5nLCBTdHJpbmc+IG1hcDEgPSBuZXcgSGFzaE1hcDw+KCk7CiAgICAgICAgTWFwPFN0cmluZywgU3RyaW5nPiBtYXAyID0gbmV3IEhhc2hNYXA8PigpOwoKICAgICAgICBtYXAxLnB1dCgiYSIsICIxIik7CiAgICAgICAgbWFwMS5wdXQoImIiLCAiMiIpOwoKICAgICAgICBtYXAyLnB1dCgiYiIsICIyIik7CiAgICAgICAgbWFwMi5wdXQoImQiLCAiNCIpOwoKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4obWFwRGlmZmVyZW5jZShtYXAyLCBtYXAxKSk7CiAgICB9Cn0=