title: De-duping Java 8 streams
body: <p>Java 8 here. I have a method <code>checkDupeKeys</code> that will take three different <code>SortedMap</code> instances as its arguments and needs to verify that no two <code>SortedMap</code> instances have identical keys. My best attempt thus far:</p>
  
  <pre><code>private void checkDupeKeys(SortedMap&lt;String, Fizz&gt; fizzes, SortedMap&lt;String, Buzz&gt; buzzes,
          SortedMap&lt;String, Foobar&gt; foobars) {}
      List&lt;String&gt; keyNames = new ArrayList&lt;&gt;();
  
      keyNames.addAll(fizzes.keySet().stream().collect(Collectors.toList()));
      keyNames.addAll(buzzes.keySet().stream().collect(Collectors.toList()));
      keyNames.addAll(foobars.keySet().stream().collect(Collectors.toList()));
  
      if(keyNames.size() &gt; keyNames.stream().collect(Collectors.toSet()).size()) {
          throw new IllegalArgumentException("Duplicate key names are not allowed.");
      }
  }
  </code></pre>
  
  <p>I <em>believe</em> this works, however there might very well be a better way of going about it (efficiency, etc.).</p>
  
  <p>My main concern is that this method doesn't allow me to identify which key names are duplicates. I'd ideally like the exception message to be:</p>
  
  <pre><code>Duplicate key names are not allowed. You have the following duplicate key names: (1) fizzes["derp"] and buzzes["derp"]. (2) fizzes["flim"] and foobars["flim"]. (3) buzzes["flam"] and foobars["flam"].
  </code></pre>
  
  <p>How can I modify my (non-static) <code>checkDupeKeys</code> method to throw an exception that meets this criteria? That is, how do I get access to which keys inside the streams are duplicates of each other. I'm sure I could do this the <em>hard way</em> using older Java collections APIs, but efficiency and leveraging Java 8 APIs are important to me in this solution.</p>