title: How to do map inversion with Guava with non-unique values?
body: <p>How can we do that with Guava? Notice the presence of <code>List&lt;K&gt;</code> in the return type since many keys can map to the same value in any normal map.</p>
  
  <pre><code>public static &lt;K, V&gt; Map&lt;V, List&lt;K&gt;&gt; inverse(Map&lt;K, V&gt; map){
      Map&lt;V, List&lt;K&gt;&gt; result = new LinkedHashMap&lt;V, List&lt;K&gt;&gt;();
      for (Map.Entry&lt;K, V&gt; entry : map.entrySet()) {
          if(!result.containsKey(entry.getValue())){
              result.put(entry.getValue(), new ArrayList&lt;K&gt;());                
          }
          result.get(entry.getValue()).add(entry.getKey());
      }        
      return result;        
  }
  </code></pre>
  
  <p><code>BiMap</code> seems to insist on the unicity of the values, but I don't have this luxury.</p>