Uses of Interface
java.util.stream.Collector
Package
Description
Classes to support functional-style operations on streams of elements, such
as map-reduce transformations on collections.
-
Uses of Collector in java.util.stream
Modifier and TypeMethodDescriptionCollectors.averagingDouble(ToDoubleFunction<? super T> mapper)
Returns aCollector
that produces the arithmetic mean of a double-valued function applied to the input elements.Collectors.averagingInt(ToIntFunction<? super T> mapper)
Returns aCollector
that produces the arithmetic mean of an integer-valued function applied to the input elements.Collectors.averagingLong(ToLongFunction<? super T> mapper)
Returns aCollector
that produces the arithmetic mean of a long-valued function applied to the input elements.static <T, A, R, RR> Collector<T,A,RR>
Collectors.collectingAndThen(Collector<T,A,R> downstream, Function<R,RR> finisher)
Adapts aCollector
to perform an additional finishing transformation.Collectors.counting()
Returns aCollector
accepting elements of typeT
that counts the number of input elements.static <T, A, R> Collector<T,?,R>
Adapts aCollector
to one accepting elements of the same typeT
by applying the predicate to each input element and only accumulating if the predicate returnstrue
.static <T, U, A, R> Collector<T,?,R>
Collectors.flatMapping(Function<? super T,? extends Stream<? extends U>> mapper, Collector<? super U,A,R> downstream)
Adapts aCollector
accepting elements of typeU
to one accepting elements of typeT
by applying a flat mapping function to each input element before accumulation.Collectors.groupingBy(Function<? super T,? extends K> classifier)
Returns aCollector
implementing a "group by" operation on input elements of typeT
, grouping elements according to a classification function, and returning the results in aMap
.Collectors.groupingBy(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)
Returns aCollector
implementing a cascaded "group by" operation on input elements of typeT
, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector
.Collectors.groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
Returns aCollector
implementing a cascaded "group by" operation on input elements of typeT
, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector
.static <T, K> Collector<T,?,ConcurrentMap<K,List<T>>>
Collectors.groupingByConcurrent(Function<? super T,? extends K> classifier)
Returns a concurrentCollector
implementing a "group by" operation on input elements of typeT
, grouping elements according to a classification function.static <T, K, A, D, M extends ConcurrentMap<K, D>>
Collector<T,?,M>Collectors.groupingByConcurrent(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)
Returns a concurrentCollector
implementing a cascaded "group by" operation on input elements of typeT
, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector
.static <T, K, A, D> Collector<T,?,ConcurrentMap<K,D>>
Collectors.groupingByConcurrent(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
Returns a concurrentCollector
implementing a cascaded "group by" operation on input elements of typeT
, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector
.static Collector<CharSequence,?,String>
Collectors.joining()
Returns aCollector
that concatenates the input elements into aString
, in encounter order.static Collector<CharSequence,?,String>
Collectors.joining(CharSequence delimiter)
Returns aCollector
that concatenates the input elements, separated by the specified delimiter, in encounter order.static Collector<CharSequence,?,String>
Collectors.joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
Returns aCollector
that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.static <T, U, A, R> Collector<T,?,R>
Adapts aCollector
accepting elements of typeU
to one accepting elements of typeT
by applying a mapping function to each input element before accumulation.Collectors.maxBy(Comparator<? super T> comparator)
Returns aCollector
that produces the maximal element according to a givenComparator
, described as anOptional<T>
.Collectors.minBy(Comparator<? super T> comparator)
Returns aCollector
that produces the minimal element according to a givenComparator
, described as anOptional<T>
.static <T, A, R> Collector<T,A,R>
Collector.of(Supplier<A> supplier, BiConsumer<A,T> accumulator, BinaryOperator<A> combiner, Function<A,R> finisher, Collector.Characteristics... characteristics)
Returns a newCollector
described by the givensupplier
,accumulator
,combiner
, andfinisher
functions.static <T, R> Collector<T,R,R>
Collector.of(Supplier<R> supplier, BiConsumer<R,T> accumulator, BinaryOperator<R> combiner, Collector.Characteristics... characteristics)
Returns a newCollector
described by the givensupplier
,accumulator
, andcombiner
functions.Collectors.partitioningBy(Predicate<? super T> predicate)
Returns aCollector
which partitions the input elements according to aPredicate
, and organizes them into aMap<Boolean, List<T>>
.Collectors.partitioningBy(Predicate<? super T> predicate, Collector<? super T,A,D> downstream)
Returns aCollector
which partitions the input elements according to aPredicate
, reduces the values in each partition according to anotherCollector
, and organizes them into aMap<Boolean, D>
whose values are the result of the downstream reduction.Collectors.reducing(BinaryOperator<T> op)
Returns aCollector
which performs a reduction of its input elements under a specifiedBinaryOperator
.static <T> Collector<T,?,T>
Collectors.reducing(T identity, BinaryOperator<T> op)
Returns aCollector
which performs a reduction of its input elements under a specifiedBinaryOperator
using the provided identity.static <T, U> Collector<T,?,U>
Collectors.reducing(U identity, Function<? super T,? extends U> mapper, BinaryOperator<U> op)
Returns aCollector
which performs a reduction of its input elements under a specified mapping function andBinaryOperator
.static <T> Collector<T,?,DoubleSummaryStatistics>
Collectors.summarizingDouble(ToDoubleFunction<? super T> mapper)
Returns aCollector
which applies andouble
-producing mapping function to each input element, and returns summary statistics for the resulting values.static <T> Collector<T,?,IntSummaryStatistics>
Collectors.summarizingInt(ToIntFunction<? super T> mapper)
Returns aCollector
which applies anint
-producing mapping function to each input element, and returns summary statistics for the resulting values.static <T> Collector<T,?,LongSummaryStatistics>
Collectors.summarizingLong(ToLongFunction<? super T> mapper)
Returns aCollector
which applies anlong
-producing mapping function to each input element, and returns summary statistics for the resulting values.Collectors.summingDouble(ToDoubleFunction<? super T> mapper)
Returns aCollector
that produces the sum of a double-valued function applied to the input elements.Collectors.summingInt(ToIntFunction<? super T> mapper)
Returns aCollector
that produces the sum of a integer-valued function applied to the input elements.Collectors.summingLong(ToLongFunction<? super T> mapper)
Returns aCollector
that produces the sum of a long-valued function applied to the input elements.static <T, R1, R2, R>
Collector<T,?,R>Collectors.teeing(Collector<? super T,?,R1> downstream1, Collector<? super T,?,R2> downstream2, BiFunction<? super R1,? super R2,R> merger)
Returns aCollector
that is a composite of two downstream collectors.static <T, C extends Collection<T>>
Collector<T,?,C>Collectors.toCollection(Supplier<C> collectionFactory)
Returns aCollector
that accumulates the input elements into a newCollection
, in encounter order.static <T, K, U> Collector<T,?,ConcurrentMap<K,U>>
Collectors.toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
Returns a concurrentCollector
that accumulates elements into aConcurrentMap
whose keys and values are the result of applying the provided mapping functions to the input elements.static <T, K, U> Collector<T,?,ConcurrentMap<K,U>>
Collectors.toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)
Returns a concurrentCollector
that accumulates elements into aConcurrentMap
whose keys and values are the result of applying the provided mapping functions to the input elements.static <T, K, U, M extends ConcurrentMap<K, U>>
Collector<T,?,M>Collectors.toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapFactory)
Returns a concurrentCollector
that accumulates elements into aConcurrentMap
whose keys and values are the result of applying the provided mapping functions to the input elements.Collectors.toList()
Returns aCollector
that accumulates the input elements into a newList
.Collectors.toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
Returns aCollector
that accumulates elements into aMap
whose keys and values are the result of applying the provided mapping functions to the input elements.Collectors.toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)
Returns aCollector
that accumulates elements into aMap
whose keys and values are the result of applying the provided mapping functions to the input elements.Collectors.toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapFactory)
Returns aCollector
that accumulates elements into aMap
whose keys and values are the result of applying the provided mapping functions to the input elements.Collectors.toSet()
Returns aCollector
that accumulates the input elements into a newSet
.Collectors.toUnmodifiableList()
Returns aCollector
that accumulates the input elements into an unmodifiable List in encounter order.Collectors.toUnmodifiableMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
Returns aCollector
that accumulates the input elements into an unmodifiable Map, whose keys and values are the result of applying the provided mapping functions to the input elements.Collectors.toUnmodifiableMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)
Returns aCollector
that accumulates the input elements into an unmodifiable Map, whose keys and values are the result of applying the provided mapping functions to the input elements.Collectors.toUnmodifiableSet()
Returns aCollector
that accumulates the input elements into an unmodifiable Set.Modifier and TypeMethodDescription<R, A> R
Performs a mutable reduction operation on the elements of this stream using aCollector
.static <T, A, R, RR> Collector<T,A,RR>
Collectors.collectingAndThen(Collector<T,A,R> downstream, Function<R,RR> finisher)
Adapts aCollector
to perform an additional finishing transformation.static <T, A, R> Collector<T,?,R>
Adapts aCollector
to one accepting elements of the same typeT
by applying the predicate to each input element and only accumulating if the predicate returnstrue
.static <T, U, A, R> Collector<T,?,R>
Collectors.flatMapping(Function<? super T,? extends Stream<? extends U>> mapper, Collector<? super U,A,R> downstream)
Adapts aCollector
accepting elements of typeU
to one accepting elements of typeT
by applying a flat mapping function to each input element before accumulation.Collectors.groupingBy(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)
Returns aCollector
implementing a cascaded "group by" operation on input elements of typeT
, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector
.Collectors.groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
Returns aCollector
implementing a cascaded "group by" operation on input elements of typeT
, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector
.static <T, K, A, D, M extends ConcurrentMap<K, D>>
Collector<T,?,M>Collectors.groupingByConcurrent(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)
Returns a concurrentCollector
implementing a cascaded "group by" operation on input elements of typeT
, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector
.static <T, K, A, D> Collector<T,?,ConcurrentMap<K,D>>
Collectors.groupingByConcurrent(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
Returns a concurrentCollector
implementing a cascaded "group by" operation on input elements of typeT
, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstreamCollector
.static <T, U, A, R> Collector<T,?,R>
Adapts aCollector
accepting elements of typeU
to one accepting elements of typeT
by applying a mapping function to each input element before accumulation.Collectors.partitioningBy(Predicate<? super T> predicate, Collector<? super T,A,D> downstream)
Returns aCollector
which partitions the input elements according to aPredicate
, reduces the values in each partition according to anotherCollector
, and organizes them into aMap<Boolean, D>
whose values are the result of the downstream reduction.static <T, R1, R2, R>
Collector<T,?,R>Collectors.teeing(Collector<? super T,?,R1> downstream1, Collector<? super T,?,R2> downstream2, BiFunction<? super R1,? super R2,R> merger)
Returns aCollector
that is a composite of two downstream collectors.