Reputation: 4833
Say I have a guava Multimap. I have a value, "Foo", that may belong to one or more keys. Is there any way I can figure out which keys contain an entry "Foo"?
Upvotes: 9
Views: 4347
Reputation: 40851
If you have an ImmutableMultimap
, which is a good idea whenever possible, you can call .inverse().get(v)
on it.
Upvotes: 7
Reputation: 15523
You can invert the Multimap. For this you can use the method Multimaps.invertFrom
.
For example, if your Multimap is a Multimap<String, String>
Multimap<String, String> invertedMultimap = Multimaps.invertFrom(myMultimap, ArrayListMultimap.<String, String>create());
Upvotes: 14