Class Collectors
java.lang.Object
java.util.stream.Collectors
The common Collectors: into collections, maps, strings, groups and
numbers.
The results are the JDK's: groupingBy answers a HashMap of
ArrayLists unless told otherwise, toMap refuses a second value for a
key unless given a function to merge them, and the unmodifiable variants
refuse null.
Every function here is a class of its own, made only by the method that needs it, so an application carries the collectors it uses and no others.
-
Method Summary
Modifier and TypeMethodDescriptionaveragingDouble(ToDoubleFunction<? super T> mapper) averagingInt(ToIntFunction<? super T> mapper) averagingLong(ToLongFunction<? super T> mapper) static <T,A, R, RR> Collector <T, A, RR> collectingAndThen(Collector<T, A, R> downstream, Function<R, RR> finisher) counting()static <T,A, R> Collector <T, ?, R> static <T,U, A, R> Collector <T, ?, R> flatMapping(Function<? super T, ? extends Stream<? extends U>> mapper, Collector<? super U, A, R> downstream) groupingBy(Function<? super T, ? extends K> classifier) groupingBy(Function<? super T, ? extends K> classifier, Supplier<M> mapFactory, Collector<? super T, A, D> downstream) groupingBy(Function<? super T, ? extends K> classifier, Collector<? super T, A, D> downstream) static Collector<CharSequence, ?, String> joining()static Collector<CharSequence, ?, String> joining(CharSequence delimiter) static Collector<CharSequence, ?, String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix) static <T,U, A, R> Collector <T, ?, R> maxBy(Comparator<? super T> comparator) minBy(Comparator<? super T> comparator) partitioningBy(Predicate<? super T> predicate) partitioningBy(Predicate<? super T> predicate, Collector<? super T, A, D> downstream) reducing(BinaryOperator<T> op) static <T> Collector<T, ?, T> reducing(T identity, BinaryOperator<T> op) static <T,U> Collector <T, ?, U> reducing(U identity, Function<? super T, ? extends U> mapper, BinaryOperator<U> op) static <T> Collector<T, ?, DoubleSummaryStatistics> summarizingDouble(ToDoubleFunction<? super T> mapper) static <T> Collector<T, ?, IntSummaryStatistics> summarizingInt(ToIntFunction<? super T> mapper) static <T> Collector<T, ?, LongSummaryStatistics> summarizingLong(ToLongFunction<? super T> mapper) summingDouble(ToDoubleFunction<? super T> mapper) summingInt(ToIntFunction<? super T> mapper) summingLong(ToLongFunction<? super T> mapper) static <T, C extends Collection<T>>
Collector<T, ?, C> toCollection(Supplier<C> collectionFactory) toList()toMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper, BinaryOperator<U> mergeFunction) toMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapFactory) toSet()toUnmodifiableMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) toUnmodifiableMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper, BinaryOperator<U> mergeFunction)
-
Method Details
-
toCollection
public static <T, C extends Collection<T>> Collector<T,?, toCollectionC> (Supplier<C> collectionFactory) -
toList
-
toUnmodifiableList
-
toSet
-
toUnmodifiableSet
-
joining
-
joining
-
joining
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix) -
mapping
-
filtering
-
flatMapping
-
collectingAndThen
-
counting
-
summingInt
-
summingLong
-
summingDouble
-
averagingInt
-
averagingLong
-
averagingDouble
-
summarizingInt
public static <T> Collector<T, ?, IntSummaryStatistics> summarizingInt(ToIntFunction<? super T> mapper) -
summarizingLong
public static <T> Collector<T, ?, LongSummaryStatistics> summarizingLong(ToLongFunction<? super T> mapper) -
summarizingDouble
public static <T> Collector<T, ?, DoubleSummaryStatistics> summarizingDouble(ToDoubleFunction<? super T> mapper) -
reducing
-
reducing
-
reducing
public static <T,U> Collector<T,?, reducingU> (U identity, Function<? super T, ? extends U> mapper, BinaryOperator<U> op) -
minBy
-
maxBy
-
groupingBy
-
groupingBy
-
groupingBy
-
partitioningBy
-
partitioningBy
-
toMap
-
toMap
public static <T,K, Collector<T,U> ?, toMapMap<K, U>> (Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper, BinaryOperator<U> mergeFunction) -
toMap
-
toUnmodifiableMap
-
toUnmodifiableMap
public static <T,K, Collector<T,U> ?, toUnmodifiableMapMap<K, U>> (Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper, BinaryOperator<U> mergeFunction)
-