public final class Collectors
extends java.lang.Object
Collector
interface.Collector
Modifier and Type | Method and Description |
---|---|
static <T> Collector<T,?,java.lang.Double> |
averagingDouble(ToDoubleFunction<? super T> mapper)
Returns a
Collector that calculates average of double-valued input elements. |
static <T> Collector<T,?,java.lang.Double> |
averagingInt(ToIntFunction<? super T> mapper)
Returns a
Collector that calculates average of integer-valued input elements. |
static <T> Collector<T,?,java.lang.Double> |
averagingLong(ToLongFunction<? super T> mapper)
Returns a
Collector that calculates average of long-valued input elements. |
static <T,A,IR,OR> |
collectingAndThen(Collector<T,A,IR> c,
Function<IR,OR> finisher)
Returns a
Collector that performs additional transformation. |
static <T> Collector<T,?,java.lang.Integer> |
counting()
Returns a
Collector that counts the number of input elements. |
static <T,A,R> Collector<T,?,R> |
filtering(Predicate<? super T> predicate,
Collector<? super T,A,R> downstream)
Returns a
Collector that filters input elements. |
static <T,U,A,R> Collector<T,?,R> |
flatMapping(Function<? super T,? extends Stream<? extends U>> mapper,
Collector<? super U,A,R> downstream)
Returns a
Collector that performs flat-mapping before accumulation. |
static <T,K> Collector<T,?,java.util.Map<K,java.util.List<T>>> |
groupingBy(Function<? super T,? extends K> classifier)
Returns a
Collector that performs grouping operation by given classifier. |
static <T,K,A,D> Collector<T,?,java.util.Map<K,D>> |
groupingBy(Function<? super T,? extends K> classifier,
Collector<? super T,A,D> downstream)
Returns a
Collector that performs grouping operation by given classifier. |
static <T,K,D,A,M extends java.util.Map<K,D>> |
groupingBy(Function<? super T,? extends K> classifier,
Collector<? super T,A,D> downstream,
Supplier<M> mapFactory)
Returns a
Collector that performs grouping operation by given classifier. |
static Collector<java.lang.CharSequence,?,java.lang.String> |
joining()
Returns a
Collector that concatenates input elements into new string. |
static Collector<java.lang.CharSequence,?,java.lang.String> |
joining(java.lang.CharSequence delimiter)
Returns a
Collector that concatenates input elements into new string. |
static Collector<java.lang.CharSequence,?,java.lang.String> |
joining(java.lang.CharSequence delimiter,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix)
Returns a
Collector that concatenates input elements into new string. |
static Collector<java.lang.CharSequence,?,java.lang.String> |
joining(java.lang.CharSequence delimiter,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix,
java.lang.String emptyValue)
Returns a
Collector that concatenates input elements into new string. |
static <T,U,A,R> Collector<T,?,R> |
mapping(Function<? super T,? extends U> mapper,
Collector<? super U,A,R> downstream)
Returns a
Collector that performs mapping before accumulation. |
static <T,R> Collector<T,?,R> |
reducing(R identity,
Function<? super T,? extends R> mapper,
BinaryOperator<R> op)
Returns a
Collector that reduces input elements. |
static <T> Collector<T,?,T> |
reducing(T identity,
BinaryOperator<T> op)
Returns a
Collector that reduces input elements. |
static <T> Collector<T,?,java.lang.Double> |
summingDouble(ToDoubleFunction<? super T> mapper)
Returns a
Collector that summing double-valued input elements. |
static <T> Collector<T,?,java.lang.Integer> |
summingInt(ToIntFunction<? super T> mapper)
Returns a
Collector that summing integer-valued input elements. |
static <T> Collector<T,?,java.lang.Long> |
summingLong(ToLongFunction<? super T> mapper)
Returns a
Collector that summing long-valued input elements. |
static <T,R extends java.util.Collection<T>> |
toCollection(Supplier<R> collectionSupplier)
Returns a
Collector that fills new Collection , provided by collectionSupplier ,
with input elements. |
static <T> Collector<T,?,java.util.List<T>> |
toList()
Returns a
Collector that fills new List with input elements. |
static <K,T> Collector<T,?,java.util.Map<K,T>> |
toMap(Function<? super T,? extends K> keyMapper)
Returns a
Collector that fills new Map with input elements. |
static <T,K,V> Collector<T,?,java.util.Map<K,V>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper)
Returns a
Collector that fills new Map with input elements. |
static <T,K,V> Collector<T,?,java.util.Map<K,V>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper,
BinaryOperator<V> mergeFunction) |
static <T,K,V,M extends java.util.Map<K,V>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper,
BinaryOperator<V> mergeFunction,
Supplier<M> mapFactory)
Returns a
Collector that fills new Map with input elements. |
static <T,K,V,M extends java.util.Map<K,V>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper,
Supplier<M> mapFactory) |
static <T> Collector<T,?,java.util.Set<T>> |
toSet()
Returns a
Collector that fills new Set with input elements. |
public static <T,R extends java.util.Collection<T>> Collector<T,?,R> toCollection(Supplier<R> collectionSupplier)
Collector
that fills new Collection
, provided by collectionSupplier
,
with input elements.T
- the type of the input elementsR
- the type of the resulting collectioncollectionSupplier
- a supplier function that provides new collectionCollector
public static <T> Collector<T,?,java.util.List<T>> toList()
Collector
that fills new List
with input elements.T
- the type of the input elementsCollector
public static <T> Collector<T,?,java.util.Set<T>> toSet()
Collector
that fills new Set
with input elements.T
- the type of the input elementsCollector
public static <K,T> Collector<T,?,java.util.Map<K,T>> toMap(Function<? super T,? extends K> keyMapper)
Collector
that fills new Map
with input elements.T
- the type of the input elements and the result type of value mapping functionK
- the result type of key mapping functionkeyMapper
- a mapping function to produce keysCollector
toMap(Function, Function, BinaryOperator, Supplier)
public static <T,K,V> Collector<T,?,java.util.Map<K,V>> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper)
Collector
that fills new Map
with input elements.T
- the type of the input elementsK
- the result type of key mapping functionV
- the result type of value mapping functionkeyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce valuesCollector
toMap(Function, Function, BinaryOperator, Supplier)
public static <T,K,V> Collector<T,?,java.util.Map<K,V>> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper, BinaryOperator<V> mergeFunction)
keyMapper
- valueMapper
- mergeFunction
- toMap(Function, Function, BinaryOperator, Supplier)
public static <T,K,V,M extends java.util.Map<K,V>> Collector<T,?,M> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper, Supplier<M> mapFactory)
keyMapper
- valueMapper
- mapFactory
- toMap(Function, Function, BinaryOperator, Supplier)
public static <T,K,V,M extends java.util.Map<K,V>> Collector<T,?,M> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper, BinaryOperator<V> mergeFunction, Supplier<M> mapFactory)
Collector
that fills new Map
with input elements.T
- the type of the input elementsK
- the result type of key mapping functionV
- the result type of value mapping functionM
- the type of the resulting Map
keyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce valuesmergeFunction
- mapFactory
- a supplier function that provides new Map
Collector
public static Collector<java.lang.CharSequence,?,java.lang.String> joining()
Collector
that concatenates input elements into new string.Collector
public static Collector<java.lang.CharSequence,?,java.lang.String> joining(java.lang.CharSequence delimiter)
Collector
that concatenates input elements into new string.delimiter
- the delimiter between each elementCollector
public static Collector<java.lang.CharSequence,?,java.lang.String> joining(java.lang.CharSequence delimiter, java.lang.CharSequence prefix, java.lang.CharSequence suffix)
Collector
that concatenates input elements into new string.delimiter
- the delimiter between each elementprefix
- the prefix of resultsuffix
- the suffix of resultCollector
public static Collector<java.lang.CharSequence,?,java.lang.String> joining(java.lang.CharSequence delimiter, java.lang.CharSequence prefix, java.lang.CharSequence suffix, java.lang.String emptyValue)
Collector
that concatenates input elements into new string.delimiter
- the delimiter between each elementprefix
- the prefix of resultsuffix
- the suffix of resultemptyValue
- the string which replaces empty element if existsCollector
public static <T> Collector<T,?,java.lang.Double> averagingInt(ToIntFunction<? super T> mapper)
Collector
that calculates average of integer-valued input elements.T
- the type of the input elementsmapper
- the mapping function which extracts value from element to calculate resultCollector
public static <T> Collector<T,?,java.lang.Double> averagingLong(ToLongFunction<? super T> mapper)
Collector
that calculates average of long-valued input elements.T
- the type of the input elementsmapper
- the mapping function which extracts value from element to calculate resultCollector
public static <T> Collector<T,?,java.lang.Double> averagingDouble(ToDoubleFunction<? super T> mapper)
Collector
that calculates average of double-valued input elements.T
- the type of the input elementsmapper
- the mapping function which extracts value from element to calculate resultCollector
public static <T> Collector<T,?,java.lang.Integer> summingInt(ToIntFunction<? super T> mapper)
Collector
that summing integer-valued input elements.T
- the type of the input elementsmapper
- the mapping function which extracts value from element to calculate resultCollector
public static <T> Collector<T,?,java.lang.Long> summingLong(ToLongFunction<? super T> mapper)
Collector
that summing long-valued input elements.T
- the type of the input elementsmapper
- the mapping function which extracts value from element to calculate resultCollector
public static <T> Collector<T,?,java.lang.Double> summingDouble(ToDoubleFunction<? super T> mapper)
Collector
that summing double-valued input elements.T
- the type of the input elementsmapper
- the mapping function which extracts value from element to calculate resultCollector
public static <T> Collector<T,?,java.lang.Integer> counting()
Collector
that counts the number of input elements.T
- the type of the input elementsCollector
public static <T> Collector<T,?,T> reducing(T identity, BinaryOperator<T> op)
Collector
that reduces input elements.T
- the type of the input elementsidentity
- the initial valueop
- the operator to reduce elementsCollector
reducing(java.lang.Object, com.annimon.stream.function.Function, com.annimon.stream.function.BinaryOperator)
public static <T,R> Collector<T,?,R> reducing(R identity, Function<? super T,? extends R> mapper, BinaryOperator<R> op)
Collector
that reduces input elements.T
- the type of the input elementsR
- the type of the output elementsidentity
- the initial valuemapper
- the mapping functionop
- the operator to reduce elementsCollector
reducing(java.lang.Object, com.annimon.stream.function.BinaryOperator)
public static <T,A,R> Collector<T,?,R> filtering(Predicate<? super T> predicate, Collector<? super T,A,R> downstream)
Collector
that filters input elements.T
- the type of the input elementsA
- the accumulation typeR
- the type of the output elementspredicate
- a predicate used to filter elementsdownstream
- the collector of filtered elementsCollector
public static <T,U,A,R> Collector<T,?,R> mapping(Function<? super T,? extends U> mapper, Collector<? super U,A,R> downstream)
Collector
that performs mapping before accumulation.T
- the type of the input elementsU
- the result type of mapping functionA
- the accumulation typeR
- the result type of collectormapper
- a function that performs mapping to input elementsdownstream
- the collector of mapped elementsCollector
public static <T,U,A,R> Collector<T,?,R> flatMapping(Function<? super T,? extends Stream<? extends U>> mapper, Collector<? super U,A,R> downstream)
Collector
that performs flat-mapping before accumulation.T
- the type of the input elementsU
- the result type of flat-mapping functionA
- the accumulation typeR
- the result type of collectormapper
- a function that performs flat-mapping to input elementsdownstream
- the collector of flat-mapped elementsCollector
public static <T,A,IR,OR> Collector<T,A,OR> collectingAndThen(Collector<T,A,IR> c, Function<IR,OR> finisher)
Collector
that performs additional transformation.T
- the type of the input elementsA
- the accumulation typeIR
- the input type of the transformation functionOR
- the output type of the transformation functionc
- the input Collector
finisher
- the final transformation functionCollector
public static <T,K> Collector<T,?,java.util.Map<K,java.util.List<T>>> groupingBy(Function<? super T,? extends K> classifier)
Collector
that performs grouping operation by given classifier.T
- the type of the input elementsK
- the type of the keysclassifier
- the classifier functionCollector
groupingBy(com.annimon.stream.function.Function, com.annimon.stream.Collector)
,
groupingBy(com.annimon.stream.function.Function, com.annimon.stream.Collector, com.annimon.stream.function.Supplier)
public static <T,K,A,D> Collector<T,?,java.util.Map<K,D>> groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)
Collector
that performs grouping operation by given classifier.T
- the type of the input elementsK
- the type of the keysA
- the accumulation typeD
- the result type of downstream reductionclassifier
- the classifier functiondownstream
- the collector of mapped elementsCollector
groupingBy(com.annimon.stream.function.Function)
,
groupingBy(com.annimon.stream.function.Function, com.annimon.stream.Collector, com.annimon.stream.function.Supplier)
public static <T,K,D,A,M extends java.util.Map<K,D>> Collector<T,?,M> groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream, Supplier<M> mapFactory)
Collector
that performs grouping operation by given classifier.T
- the type of the input elementsK
- the type of the keysA
- the accumulation typeD
- the result type of downstream reductionM
- the type of the resulting Map
classifier
- the classifier functiondownstream
- the collector of mapped elementsmapFactory
- a supplier function that provides new Map
Collector
groupingBy(com.annimon.stream.function.Function)
,
groupingBy(com.annimon.stream.function.Function, com.annimon.stream.Collector)