Reputation:
Is there a way to elegantly merge two guava multimaps with the same key value pairs in java 8?
I have tried using .collect(Multimaps.toMultimap()) with no luck.
Upvotes: 6
Views: 1982
Reputation: 50716
There are a few ways; this is the cleanest one I could find:
list.stream().collect(ArrayListMultimap::create, Multimap::putAll, Multimap::putAll)
Feel free to replace ArrayListMultimap
with some other implementation.
Upvotes: 7