Java 8 collector for Guava immutable collections?(用于 Guava 不可变集合的 Java 8 收集器?)
问题描述
我真的很喜欢 Java 8 流和 Guava 的不可变集合,但我不知道如何将两者结合使用.
I really like Java 8 streams and Guava's immutable collections, but I can't figure out how to use the two together.
例如,如何实现 Java 8 收集器,将流结果收集到 ImmutableMultimap?
For example, how do I implement a Java 8 Collector that gathers stream results into an ImmutableMultimap?
加分:我希望能够提供键/值映射器,类似于 Collectors.toMap() 有效.
Bonus points: I'd like to be able to provide key/value mappers, similar to how Collectors.toMap() works.
推荐答案
从21版开始,可以
.collect(ImmutableSet.toImmutableSet())
.collect(ImmutableMap.toImmutableMap())
.collect(Maps.toImmutableEnumMap())
.collect(Sets.toImmutableEnumSet())
.collect(Tables.toTable())
.collect(ImmutableList.toImmutableList())
.collect(Multimaps.toMultimap(...))
这篇关于用于 Guava 不可变集合的 Java 8 收集器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于 Guava 不可变集合的 Java 8 收集器?
基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
