5

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.

shmosel
  • 49,289
  • 6
  • 73
  • 138

1 Answers1

6

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.

shmosel
  • 49,289
  • 6
  • 73
  • 138