title: How can I transform a collection into a Guava Multimap grouped by the elements of a nested collection property?
body: <p>I have a <code>List&lt;Foo&gt;</code> and want a Guava <a href="https://guava.dev/releases/29.0-jre/api/docs/com/google/common/collect/Multimap.html" rel="nofollow noreferrer"><code>Multimap&lt;String, Foo&gt;</code></a> where we've grouped the <code>Foo</code>s by each tag of their <code>Collection&lt;String&gt; getTags()</code> function.</p>
  
  <p>I am using Java 8, so lambdas and method references are fine/encouraged.</p>
  
  <p>For example if I have:</p>
  
  <pre><code>foo1, tags=a,b,c
  foo2, tags=c,d
  foo3, tags=a,c,e
  </code></pre>
  
  <p>I would get a <code>Multimap&lt;String, Foo&gt;</code> with:</p>
  
  <pre><code>a -&gt; foo1, foo3
  b -&gt; foo1
  c -&gt; foo1, foo2, foo3
  d -&gt; foo2
  e -&gt; foo3
  </code></pre>