title: Java 8 List<V> into Map<K, V>
body: <p>I want to translate a List of objects into a Map using Java 8's streams and lambdas.</p>
  
  <p>This is how I would write it in Java 7 and below.</p>
  
  <pre><code>private Map&lt;String, Choice&gt; nameMap(List&lt;Choice&gt; choices) {
          final Map&lt;String, Choice&gt; hashMap = new HashMap&lt;&gt;();
          for (final Choice choice : choices) {
              hashMap.put(choice.getName(), choice);
          }
          return hashMap;
  }
  </code></pre>
  
  <p>I can accomplish this easily using Java 8 and Guava but I would like to know how to do this without Guava.</p>
  
  <p>In Guava:</p>
  
  <pre><code>private Map&lt;String, Choice&gt; nameMap(List&lt;Choice&gt; choices) {
      return Maps.uniqueIndex(choices, new Function&lt;Choice, String&gt;() {
  
          @Override
          public String apply(final Choice input) {
              return input.getName();
          }
      });
  }
  </code></pre>
  
  <p>And Guava with Java 8 lambdas.</p>
  
  <pre><code>private Map&lt;String, Choice&gt; nameMap(List&lt;Choice&gt; choices) {
      return Maps.uniqueIndex(choices, Choice::getName);
  }
  </code></pre>