title: Compare two Maps and remove all the elements that either have the same key or the same value
body: <p>I have two Maps that I need to compare and merge them into a result map. I need to remove all the elements that either have the same key or the same value. </p>
  
  <p>Basically, say I have two Maps:</p>
  
  <pre><code>Map&lt;String, String&gt; map1 = new HashMap&lt;&gt;();
  map1.put("1", "A");
  map1.put("2", "A");
  map1.put("3", "B");
  map1.put("4", "C");
  map1.put("5", "D");
  map1.put("6", "E");
  
  Map&lt;String, String&gt; map2 = new HashMap&lt;&gt;();
  map2.put("1", "B");
  map2.put("2", "A");
  map2.put("4", "F");
  map2.put("6", "C");
  map2.put("7", "G");
  map2.put("8", "H");
  </code></pre>
  
  <p>I need to remove all the entries that have either the same keys or the same values and need to retain back only bidirectional unique entries. So after merge, I need to have the following result map in which every key maps to a unique value and every value has a unique key:</p>
  
  <pre><code>("5", "D"), ("7", "G"), ("8", "H")
  </code></pre>
  
  <p>What's the best way to do this in Java?</p>