title: Java Lambda Stream List<User> to Map<Role, List<User>>
body: <p>I have to write a method which takes a <code>List&lt;User&gt;</code> and returns a <code>Map&lt;Role,List&lt;User&gt;&gt;</code>.<br></p>
  
  <p><code>User</code> contains a <code>Person</code> instance, which contains a <code>Role</code>.<br>
  I must create a map where Role key is mapped to a list of users (where user has this Role).</p>
  
  <p>I tried the following :</p>
  
  <pre><code>public static Map&lt;Role, List&lt;User&gt;&gt; groupUsersByRole(List&lt;User&gt; users) {
      users.stream().collect(Collectors.toMap((u -&gt; u.getPersonDetails().getRole()), users.stream().collect(Collectors.toList()  ) )
      users.stream().map(user -&gt; user).filter(u -&gt; u.).collect(Collectors.toList()) );
      //users.stream().filter(u -&gt; u.getPersonDetails().getRole().getName().equals(u.getPersonDetails().getRole().getName())).map(user -&gt; user.getName()).
      return null;
  }
  </code></pre>