Java stream reverse a multimap
<p>Concept: two types <code>A</code> and <code>B</code>, each may map to multiple elements of the other type.</p>

<p>Suppose I have an input list: <code>List&lt;A&gt; aList</code>, how to generate a map <code>Map&lt;B, List&lt;A&gt;&gt; result</code> with Java 8 stream?</p>

<pre><code>Map&lt;B, List&lt;A&gt;&gt; result = aList.stream().flatMap(a -&gt; a.getBs().stream().map(b -&gt; new Tuple2&lt;&gt;(b, a)) // just create pairs of (B, A) for each a
                              .collect(Collectors.groupingBy(???)); // then group these pairs by b
</code></pre>

<p>Or would Guava or Apache Comms provide such functionality?</p>

<p>Thanks!</p>

<p><strong>UPDATE:</strong></p>

<p>Thanks to @Tukani, please look at <a href="https://stackoverflow.com/questions/38471056/">this post</a> for answer.</p>