title: HashMap in Unary Functional Interface with Lambda in Java 8
body: <p>I'm studying for Java 8 Lambda and Unary Functional Interface. I have a practice assignment about "Function" class using <code>HashMap</code>, which the following steps to do:</p>
  
  <ol>
  <li><p>Create a variable of type <code>Function&lt;Set, Map&gt;</code> that receives a <code>Set</code> and creates a <code>HashMap</code> using lambda expressions</p></li>
  <li><p>Put words in the map, using as key the uppercase first letter of that word</p></li>
  <li><p>Execute lambda expression and view the result</p></li>
  </ol>
  
  <p>I trying in the following way, but it doesn't work. I think that the problem is in the lambda expression, but I want to understand how I have to do (for simplicity I put the same word as key). In this way, the result is "null".</p>
  
  <pre><code>import java.util.*;
  import java.util.function.Function;
  
  public class FunctionTest {
  
  public static void main(String[] args) {
          HashSet&lt;String&gt; hs = new HashSet&lt;String&gt;();
          hs.add("ciao");
          hs.add("hello");
          hs.add("hallo");
          hs.add("bonjour");
  
          Function&lt;Set, Map&gt; setToMap = s2 -&gt; (Map) new HashMap().put(s2,s2);
  
          System.out.println(setToMap.apply(hs));
     }
  }
  </code></pre>
  
  <p>For the above example, the expected result should be <code>{B=bonjour, C=ciao, H=hello}</code>.</p>