user1870035
user1870035

Reputation:

Merge Two Guava Multimaps

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

Answers (1)

shmosel
shmosel

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

Related Questions