title: How to convert List<V> into Map<K, List<V>>, with Java 8 streams and custom List and Map suppliers?
body: <p>It's easy to convert <code>List&lt;V&gt;</code> into <code>Map&lt;K, List&lt;V&gt;&gt;</code>. For example:</p>
  
  <pre><code>public Map&lt;Integer, List&lt;String&gt;&gt; getMap(List&lt;String&gt; strings) {
     return
        strings.stream()
               .collect(Collectors.groupingBy(String::length));
  }
  </code></pre>
  
  <p>But I want to do it with my own <code>List</code> and <code>Map</code> <strong>suppliers</strong>.</p>
  
  <p>I have come up with this:</p>
  
  <pre><code>public Map&lt;Integer, List&lt;String&gt;&gt; getMap(List&lt;String&gt; strings) {
     return strings.stream()
         .collect(Collectors.toMap(
               String::length,
               item -&gt; {List&lt;String&gt; list = new ArrayList&lt;&gt;(); list.add(item); return list;},
               (list1, list2) -&gt; {list1.addAll(list2); return list1;},
               HashMap::new));
  }
  </code></pre>
  
  <p><strong>Question:</strong> Is there an easier, less verbose, or more efficient way of doing it? For example, something like this (which doesn't work):</p>
  
  <pre><code>return strings.stream()
        .collect(Collectors.toMap(
              String::length,
              ArrayList::new,                    
              HashMap::new));
  </code></pre>
  
  <p>And what if I only need to define the <code>List</code> supplier, but not the <code>Map</code> supplier?</p>