title: Java 8 Convert HashSet to HashMap
body: <p>I'm trying to convert <code>hashset</code> to <code>hashmap</code> in Java 8 using lambda and Collectors but I'm failing to do so. Below is my code : </p>
  
  <pre><code>Set&lt;String&gt; set = new HashSet&lt;String&gt;();
  set.add("1");
  set.add("2");
  set.add("3");
  HashMap&lt;String, Integer&gt; map = set.stream().collect(Collectors.toMap(x -&gt; x, 0));
  </code></pre>
  
  <p>But the above is giving error as following:</p>
  
  <pre><code>The method toMap(Function&lt;? super T,? extends K&gt;, Function&lt;? super T,? extends U&gt;) in the type Collectors is not applicable for the arguments ((&lt;no type&gt; x) -&gt; {}, int)
  </code></pre>
  
  <p>I'm a newbie in lambdas. Any help?</p>