Java 8收集器可用于Guava不可变集合吗?

吉利:

我真的很喜欢Java 8流和Guava的不可变集合,但是我不知道如何将两者一起使用。

例如,如何实现将流结果收集到ImmutableMultimap中的Java 8 Collector

优点:我希望能够提供键/值映射器,类似于Collectors.toMap()的工作方式。

6号:

从21版开始,您可以

.collect(ImmutableSet.toImmutableSet())
.collect(ImmutableMap.toImmutableMap())
.collect(Maps.toImmutableEnumMap())
.collect(Sets.toImmutableEnumSet())
.collect(Tables.toTable())
.collect(ImmutableList.toImmutableList())
.collect(Multimaps.toMultimap(...))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章