title: Java Stream - Convert List to Map using toMap
body: <p>I am new to stream() and thinking of refactoring the following code with <code>stream()</code>.</p>
  <pre class="lang-java prettyprint-override"><code>public class User {
      private Integer id;
      private String name;
      private Date birthDate;
  }
  
  public class Post {
      private String content;
      private User user;
  }
  
  // I have a list of Users
  List&lt;User&gt; users = new ArrayList&lt;&gt;();
  
  // Goal is to initialize a Map of users -&gt; List&lt;Post&gt;
  Map&lt;User, List&lt;Post&gt;&gt; map = new HashMap&lt;&gt;();
  for (User user : users) {
      map.put(user, new ArrayList&lt;&gt;());
  }
  
  </code></pre>
  <p>I tried the following but doesn't work out.</p>
  <pre class="lang-java prettyprint-override"><code>Map&lt;String, List&lt;Post&gt;&gt; map = users.stream()
                  .collect(Collectors.toMap(user, new ArrayList&lt;&gt;()));
  </code></pre>
  <p>Any suggestion on how to make it right?
  Thanks!</p>