title: Java 8 stream to collect a Map of List of items
body: <p>I have a List of Maps which stores the roles and the names of people. For ex:</p>
  
  <pre><code>List&lt;Map&lt;String, String&gt;&gt; listOfData
  
  1) Role:  Batsman
     Name:  Player1
  
  2)Role:  Batsman
     Name:  Player2
  
  3)Role:  Bowler
     Name:  Player3
  </code></pre>
  
  <p>Role and Name are the Keys of the map.
  I want to convert this into a <code>Map&lt;String, List&lt;String&gt;&gt; result</code>, which will give me a list of names for each role, i.e</p>
  
  <pre><code>k1: Batsman  v1: [Player1, Player2]
  k2: Bowler   v2: [Player3]
  
  
  listOfData
      .stream()
      .map(entry -&gt; new AbstractMap.SimpleEntry&lt;&gt;(entry.get("Role"), entry.get("Name"))
      .collect(Collectors.toList());
  </code></pre>
  
  <p>Doing this way will not give me a list of names for the role, it will give me a single name. How do i keep collecting the elements of the list and then add it to a key ?</p>
  
  <p>Java code to create base structure:</p>
  
  <pre><code>Map&lt;String, String&gt; x1 = ImmutableMap.of("Role", "Batsman", "Name", "Player1");
  
          Map&lt;String, String&gt; y1 = ImmutableMap.of("Role", "Batsman", "Name", "Player2");
  
          Map&lt;String, String&gt; z1 = ImmutableMap.of("Role", "Bowler", "Name", "Player3");
  
  
          List&lt;Map&lt;String, String&gt;&gt; list = ImmutableList.of(x1, y1, z1);
          Map&lt;String, List&lt;String&gt;&gt; z = list.stream()
                      .flatMap(e -&gt; e.entrySet().stream())
                      .collect(Collectors.groupingBy(Map.Entry::getKey,
                              Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
  </code></pre>