[英]Merge Two Guava Multimaps
Is there a way to elegantly merge two guava multimaps with the same key value pairs in java 8? 有没有办法在Java 8中优雅地合并两个具有相同键值对的番石榴多图?
I have tried using .collect(Multimaps.toMultimap()) with no luck. 我已经尝试过使用.collect(Multimaps.toMultimap()),但是没有运气。
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. 随时将
ArrayListMultimap
替换为其他实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.