title: Java 8 group map by key
body: <p>I want to group a map object by key. I try with this code but i have a compile error:</p>
  
  <pre><code>Non-static method cannot be referenced from a static context
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>Map&lt;String, List&lt;A&gt;&gt; getAMap() {        
      return Arrays.stream(SomeArray.values())
              .map(map -&gt; createObject())
              .collect(Collectors.groupingBy(Map.Entry::getKey, 
                    Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
  }
  
  
  private Map&lt;String, A&gt; createObject() 
      final A a = new A(some attributes);
      Map&lt;String, A&gt; map = new LinkedHashMap&lt;&gt;();
      map.put(some key, a);
      .... // add another values. 
      return map;
  }
  </code></pre>
  
  <p>I need something like</p>
  
  <pre><code>{
  "a", {a1, a2, a3},
  "b", {a4, a5, a6},
  }
  </code></pre>