title: Convert a set to map in java
body: <p>I have a set and I want to convert it to map in order to use it later in guava's <code>Maps.difference()</code>. I only care about the keys in the difference.<br>
  Came up with this version:</p>
  
  <pre><code>private &lt;T&gt; Map&lt;T, T&gt; toMap(Set&lt;T&gt; set) {
    return set.stream().collect(Collectors.toMap(Function.identity(), Function.identity()));
  }
  </code></pre>
  
  <p>However, I know that usually, a set has a backing field of map. This is the method I use to create the map:</p>
  
  <pre><code>public static &lt;E&gt; Set&lt;E&gt; newConcurrentHashSet() {
    return Collections.newSetFromMap(new ConcurrentHashMap&lt;E, Boolean&gt;());
  }
  </code></pre>
  
  <p>Since I only need the keys I thought maybe I can get a view of this field somehow. any idea?</p>