我们如何通过使用Java Streams以最优化的方式将List<Foo>转换为Map<propertyA,List<propertyB>>。
注意:propertyA不是唯一的
//pseudo-code
class Foo
propertyA //not unique
List<propertyB>
到目前为止,我有以下内容:
fooList.stream()
.collect(Collectors.groupingBy(Foo::propertyA,
Collectors.mapping(Foo::propertyB, Collectors.toList())))
结果会得到一个尚未展开其值的Map<属性A,List<List<属性B>>>
。
flatMapping
的后移版本。 - Holger