fork(49) download
  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. class Ideone {
  5. public static <K, V> Map<K, V> mapDifference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right) {
  6. Map<K, V> difference = new HashMap<>();
  7. difference.putAll(left);
  8. difference.putAll(right);
  9. difference.entrySet().removeAll(right.entrySet());
  10. return difference;
  11. }
  12.  
  13. public static void main(String[] args) {
  14. Map<String, String> map1 = new HashMap<>();
  15. Map<String, String> map2 = new HashMap<>();
  16.  
  17. map1.put("a", "1");
  18. map1.put("b", "2");
  19.  
  20. map2.put("b", "2");
  21. map2.put("d", "4");
  22.  
  23. System.out.println(mapDifference(map2, map1));
  24. }
  25. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
{d=4}