本文整理汇总了Java中java.util.stream.Collectors.mapping方法的典型用法代码示例。如果您正苦于以下问题:Java Collectors.mapping方法的具体用法?Java Collectors.mapping怎么用?Java Collectors.mapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.stream.Collectors
的用法示例。
在下文中一共展示了Collectors.mapping方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toBiCollection
import java.util.stream.Collectors; //导入方法依赖的package包/类
/**
* Returns a {@code Collector} that extracts the pairs from the input stream,
* and then collects them into a {@code BiCollection}.
*
* @param leftFunction extracts the first element of each pair
* @param rightFunction extracts the second element of each pair
* @param collectorStrategy determines the kind of collection to use. For example:
* {@code Collectors::toList} or {@code ImmutableList::toImmutableList}.
*/
public static <T, L, R> Collector<T, ?, BiCollection<L, R>> toBiCollection(
Function<? super T, ? extends L> leftFunction,
Function<? super T, ? extends R> rightFunction,
CollectorStrategy collectorStrategy) {
requireNonNull(leftFunction);
requireNonNull(rightFunction);
Function<T, Map.Entry<L, R>> toEntry = x -> kv(leftFunction.apply(x), rightFunction.apply(x));
Collector<T, ?, ? extends Collection<? extends Map.Entry<? extends L, ? extends R>>> entryCollector =
Collectors.mapping(toEntry, collectorStrategy.collector());
return Collectors.collectingAndThen(entryCollector, BiCollection::from);
}