本文整理匯總了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);
}