Collectors
constCollectors:object
Defined in: src/stream/Collectors.ts:606
Ready-made Collectors for stream.collect: into collections and maps, string joining, counting, sums,
averages and statistics, min/max and reductions, grouping and partitioning, and adapters (mapping,
filtering, flatMapping, collectingAndThen, teeing) that compose into one-pass aggregations. Function
arguments that are null throw NullPointerException when the collector first calls them.
Type Declaration
Section titled “Type Declaration”averagingDouble
Section titled “averagingDouble”averagingDouble: <
T>(mapper) =>Collector<T,any,number>
Returns a collector of the arithmetic mean of mapper over the elements (compensated summation); 0 when empty.
Compensated summation, as the reference. 0 when no elements.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”Collector<T, any, number>
averagingInt
Section titled “averagingInt”averagingInt: <
T>(mapper) =>Collector<T,any,number>
Returns a collector of the arithmetic mean of mapper over the elements; 0 when empty.
0 when no elements.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”Collector<T, any, number>
averagingLong
Section titled “averagingLong”averagingLong: <
T>(mapper) =>Collector<T,any,number>
Returns a collector of the arithmetic mean of mapper over the elements; 0 when empty.
0 when no elements.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”Collector<T, any, number>
collectingAndThen
Section titled “collectingAndThen”collectingAndThen: <
T,A,R,RR>(downstream,finisher) =>Collector<T,A,RR>
Returns a collector that applies finisher to the result of downstream; IDENTITY_FINISH is dropped.
Type Parameters
Section titled “Type Parameters”T
A
R
RR
Parameters
Section titled “Parameters”downstream
Section titled “downstream”Collector<T, A, R>
finisher
Section titled “finisher”(r) => RR
Returns
Section titled “Returns”Collector<T, A, RR>
Throws
Section titled “Throws”NullPointerException if downstream or finisher is null
counting
Section titled “counting”counting: <
T>() =>Collector<T,any,number>
Returns a collector that counts the elements; 0 for an empty stream.
Type Parameters
Section titled “Type Parameters”T
Returns
Section titled “Returns”Collector<T, any, number>
filtering
Section titled “filtering”filtering: <
T,A,R>(predicate,downstream) =>Collector<T,A,R>
Returns a collector that passes only the elements matching predicate to downstream. As a groupingBy
downstream it keeps groups whose elements were all filtered out (with an empty result), unlike a filter before.
Type Parameters
Section titled “Type Parameters”T
A
R
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(t) => boolean
downstream
Section titled “downstream”Collector<T, A, R>
Returns
Section titled “Returns”Collector<T, A, R>
flatMapping
Section titled “flatMapping”flatMapping: <
T,U,A,R>(mapper,downstream) =>Collector<T,A,R>
Returns a collector that passes every element of the stream mapper returns to downstream. A null/undefined
result counts as empty; each mapped stream is closed after its elements are consumed.
Each mapped stream is closed after its elements are consumed; a null/undefined result counts as empty.
Type Parameters
Section titled “Type Parameters”T
U
A
R
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => ClosableSource<U> | null | undefined
downstream
Section titled “downstream”Collector<U, A, R>
Returns
Section titled “Returns”Collector<T, A, R>
groupingBy
Section titled “groupingBy”groupingBy: {<
T,K>(classifier):Collector<T,any,Map<K,List<T>>>; <T,K,A,D>(classifier,downstream):Collector<T,any,Map<K,D>>; <T,K,D,A,M>(classifier,mapFactory,downstream):Collector<T,any,M>; }
Returns a collector that groups the elements by classifier into a map from each key to its bucket’s downstream
result (default toList(), so each bucket is an ArrayList in encounter order). The default map is a HashMap,
whose iteration order is not defined; pass mapFactory (for example () => new TreeMap()) to choose one.
Call Signature
Section titled “Call Signature”<
T,K>(classifier):Collector<T,any,Map<K,List<T>>>
Groups the elements by classifier into a HashMap from each key to a List of the elements with that key, in
encounter order.
Type Parameters
Section titled “Type Parameters”T
K
Parameters
Section titled “Parameters”classifier
Section titled “classifier”(t) => K
Returns
Section titled “Returns”Collector<T, any, Map<K, List<T>>>
Throws
Section titled “Throws”NullPointerException “element cannot be mapped to a null key” if classifier returns null
Call Signature
Section titled “Call Signature”<
T,K,A,D>(classifier,downstream):Collector<T,any,Map<K,D>>
Groups by classifier into a HashMap, reducing each bucket with downstream.
Type Parameters
Section titled “Type Parameters”T
K
A
D
Parameters
Section titled “Parameters”classifier
Section titled “classifier”(t) => K
downstream
Section titled “downstream”Collector<T, A, D>
Returns
Section titled “Returns”Collector<T, any, Map<K, D>>
Call Signature
Section titled “Call Signature”<
T,K,D,A,M>(classifier,mapFactory,downstream):Collector<T,any,M>
Groups by classifier into the map mapFactory() creates, reducing each bucket with downstream.
Type Parameters
Section titled “Type Parameters”T
K
D
A
M extends Map<K, D>
Parameters
Section titled “Parameters”classifier
Section titled “classifier”(t) => K
mapFactory
Section titled “mapFactory”() => M
downstream
Section titled “downstream”Collector<T, A, D>
Returns
Section titled “Returns”Collector<T, any, M>
Throws
Section titled “Throws”NullPointerException “element cannot be mapped to a null key” if the classifier returns null
groupingByConcurrent
Section titled “groupingByConcurrent”groupingByConcurrent: {<
T,K>(classifier):Collector<T,any,Map<K,List<T>>>; <T,K,A,D>(classifier,downstream):Collector<T,any,Map<K,D>>; <T,K,D,A,M>(classifier,mapFactory,downstream):Collector<T,any,M>; }
Returns a collector with the same results as groupingBy, reported as CONCURRENT and UNORDERED. The
default map is a HashMap (concurrency is moot on one thread).
Call Signature
Section titled “Call Signature”<
T,K>(classifier):Collector<T,any,Map<K,List<T>>>
Same results as groupingBy (single-threaded runtime), reported as CONCURRENT and UNORDERED. The default map is a HashMap standing in for a concurrent hash map (so null-valued results are not rejected).
Type Parameters
Section titled “Type Parameters”T
K
Parameters
Section titled “Parameters”classifier
Section titled “classifier”(t) => K
Returns
Section titled “Returns”Collector<T, any, Map<K, List<T>>>
Call Signature
Section titled “Call Signature”<
T,K,A,D>(classifier,downstream):Collector<T,any,Map<K,D>>
As groupingBy(classifier, downstream), reported as CONCURRENT and UNORDERED.
Type Parameters
Section titled “Type Parameters”T
K
A
D
Parameters
Section titled “Parameters”classifier
Section titled “classifier”(t) => K
downstream
Section titled “downstream”Collector<T, A, D>
Returns
Section titled “Returns”Collector<T, any, Map<K, D>>
Call Signature
Section titled “Call Signature”<
T,K,D,A,M>(classifier,mapFactory,downstream):Collector<T,any,M>
As groupingBy(classifier, mapFactory, downstream), reported as CONCURRENT and UNORDERED.
Type Parameters
Section titled “Type Parameters”T
K
D
A
M extends Map<K, D>
Parameters
Section titled “Parameters”classifier
Section titled “classifier”(t) => K
mapFactory
Section titled “mapFactory”() => M
downstream
Section titled “downstream”Collector<T, A, D>
Returns
Section titled “Returns”Collector<T, any, M>
Throws
Section titled “Throws”NullPointerException “element cannot be mapped to a null key” if the classifier returns null
joining
Section titled “joining”joining: {():
Collector<string|null,any,string>; (delimiter):Collector<string|null,any,string>; (delimiter,prefix,suffix):Collector<string|null,any,string>; }
Returns a collector that concatenates the elements into a string, in encounter order. Optional delimiter
between elements, and prefix/suffix around the whole (all three or just the delimiter); an empty stream gives
prefix + suffix. A null element is written as "null", other non-strings through their toString.
Call Signature
Section titled “Call Signature”():
Collector<string|null,any,string>
Concatenates the elements with nothing between them.
Returns
Section titled “Returns”Collector<string | null, any, string>
Call Signature
Section titled “Call Signature”(
delimiter):Collector<string|null,any,string>
Concatenates the elements with delimiter between them.
Parameters
Section titled “Parameters”delimiter
Section titled “delimiter”string
Returns
Section titled “Returns”Collector<string | null, any, string>
Call Signature
Section titled “Call Signature”(
delimiter,prefix,suffix):Collector<string|null,any,string>
Concatenates the elements with delimiter between them, wrapped in prefix and suffix. A null/undefined argument throws NullPointerException when the collector is used, like the reference.
Parameters
Section titled “Parameters”delimiter
Section titled “delimiter”string
prefix
Section titled “prefix”string
suffix
Section titled “suffix”string
Returns
Section titled “Returns”Collector<string | null, any, string>
Throws
Section titled “Throws”NullPointerException (when used) if delimiter, prefix or suffix is null or undefined
mapping
Section titled “mapping”mapping: <
T,U,A,R>(mapper,downstream) =>Collector<T,A,R>
Returns a collector that applies mapper to each element and passes the result to downstream; the result is
the downstream’s. Mostly used as a downstream of groupingBy / partitioningBy.
Type Parameters
Section titled “Type Parameters”T
U
A
R
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => U
downstream
Section titled “downstream”Collector<U, A, R>
Returns
Section titled “Returns”Collector<T, A, R>
maxBy: <
T>(comparator) =>Collector<T,any,Optional<NonNullable<T>>>
Returns a collector of the largest element by comparator (the first of equal ones) as an Optional, empty
for an empty stream. A null result gives an empty optional.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”comparator
Section titled “comparator”Comparator<T>
Returns
Section titled “Returns”Collector<T, any, Optional<NonNullable<T>>>
Throws
Section titled “Throws”NullPointerException if comparator is null
minBy: <
T>(comparator) =>Collector<T,any,Optional<NonNullable<T>>>
Returns a collector of the smallest element by comparator (the first of equal ones) as an Optional, empty
for an empty stream. A null result gives an empty optional.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”comparator
Section titled “comparator”Comparator<T>
Returns
Section titled “Returns”Collector<T, any, Optional<NonNullable<T>>>
Throws
Section titled “Throws”NullPointerException if comparator is null
partitioningBy
Section titled “partitioningBy”partitioningBy: {<
T>(predicate):Collector<T,any,Map<boolean,List<T>>>; <T,D,A>(predicate,downstream):Collector<T,any,Map<boolean,D>>; }
Returns a collector that splits the elements by predicate into an unmodifiable map with exactly two keys, false
then true, both always present; each value is the downstream result (default toList()).
Call Signature
Section titled “Call Signature”<
T>(predicate):Collector<T,any,Map<boolean,List<T>>>
The result always maps both false and true.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(t) => boolean
Returns
Section titled “Returns”Collector<T, any, Map<boolean, List<T>>>
Call Signature
Section titled “Call Signature”<
T,D,A>(predicate,downstream):Collector<T,any,Map<boolean,D>>
Partitions by predicate, reducing both partitions with downstream.
Type Parameters
Section titled “Type Parameters”T
D
A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(t) => boolean
downstream
Section titled “downstream”Collector<T, A, D>
Returns
Section titled “Returns”Collector<T, any, Map<boolean, D>>
reducing
Section titled “reducing”reducing: {<
T>(op):Collector<T,any,Optional<NonNullable<T>>>; <T>(identity,op):Collector<T,any,T>; <T,U>(identity,mapper,op):Collector<T,any,U>; }
Returns the collector form of stream.reduce, mostly used as a downstream. reducing(op) gives an Optional
(empty when there are no elements or the result is null); reducing(identity, op) gives identity folded with
every element; reducing(identity, mapper, op) maps each element first.
Call Signature
Section titled “Call Signature”<
T>(op):Collector<T,any,Optional<NonNullable<T>>>
Reduces with op; an empty Optional when there are no elements (or the result is null).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”(a, b) => T
Returns
Section titled “Returns”Collector<T, any, Optional<NonNullable<T>>>
Call Signature
Section titled “Call Signature”<
T>(identity,op):Collector<T,any,T>
Reduces with op starting from identity; identity when there are no elements.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”identity
Section titled “identity”T
(a, b) => T
Returns
Section titled “Returns”Collector<T, any, T>
Call Signature
Section titled “Call Signature”<
T,U>(identity,mapper,op):Collector<T,any,U>
Maps each element with mapper, then reduces with op starting from identity.
Type Parameters
Section titled “Type Parameters”T
U
Parameters
Section titled “Parameters”identity
Section titled “identity”U
mapper
Section titled “mapper”(t) => U
(a, b) => U
Returns
Section titled “Returns”Collector<T, any, U>
summarizingDouble
Section titled “summarizingDouble”summarizingDouble: <
T>(mapper) =>Collector<T,DoubleSummaryStatistics,DoubleSummaryStatistics>
Returns a collector of a DoubleSummaryStatistics (compensated sums) of mapper over the elements.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”Collector<T, DoubleSummaryStatistics, DoubleSummaryStatistics>
summarizingInt
Section titled “summarizingInt”summarizingInt: <
T>(mapper) =>Collector<T,IntSummaryStatistics,IntSummaryStatistics>
Returns a collector of an IntSummaryStatistics (count, sum, min, max, average) of mapper over the elements.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”Collector<T, IntSummaryStatistics, IntSummaryStatistics>
summarizingLong
Section titled “summarizingLong”summarizingLong: <
T>(mapper) =>Collector<T,LongSummaryStatistics,LongSummaryStatistics>
Returns a collector of a LongSummaryStatistics (count, sum, min, max, average) of mapper over the elements.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”Collector<T, LongSummaryStatistics, LongSummaryStatistics>
summingDouble
Section titled “summingDouble”summingDouble: <
T>(mapper) =>Collector<T,any,number>
Returns a collector of the sum of mapper over the elements, using compensated (Kahan) summation; 0 when empty.
Compensated (Kahan) summation, as the reference; an infinite plain sum wins over a NaN compensated one.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”Collector<T, any, number>
summingInt
Section titled “summingInt”summingInt: <
T>(mapper) =>Collector<T,any,number>
Returns a collector of the sum of mapper over the elements; 0 when empty. A plain sum: it does not wrap on 32-bit
overflow (a difference from the reference).
Plain sum of mapper results; like IntStream.sum() here, int overflow does not wrap (documented difference).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”Collector<T, any, number>
summingLong
Section titled “summingLong”summingLong: <
T>(mapper) =>Collector<T,any,number>
Returns a collector of the sum of mapper over the elements; 0 when empty. Exact up to Number.MAX_SAFE_INTEGER.
Plain sum; exact up to Number.MAX_SAFE_INTEGER.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(t) => number
Returns
Section titled “Returns”Collector<T, any, number>
teeing
Section titled “teeing”teeing: <
T,R1,R2,R>(downstream1,downstream2,merger) =>Collector<T,any,R>
Returns a collector that sends every element to both downstream1 and downstream2 and returns
merger(result1, result2): two aggregations in one pass. Its characteristics are those both report, minus
IDENTITY_FINISH.
Feeds every element to both downstreams and merges their results. Characteristics: the intersection of both, minus IDENTITY_FINISH.
Type Parameters
Section titled “Type Parameters”T
R1
R2
R
Parameters
Section titled “Parameters”downstream1
Section titled “downstream1”Collector<T, any, R1>
downstream2
Section titled “downstream2”Collector<T, any, R2>
merger
Section titled “merger”(r1, r2) => R
Returns
Section titled “Returns”Collector<T, any, R>
Throws
Section titled “Throws”NullPointerException if an argument, or a function a downstream returns, is null
toCollection
Section titled “toCollection”toCollection: <
T,C>(collectionFactory) =>Collector<T,C,C>
Returns a collector that adds the elements, in encounter order, to the collection collectionFactory() creates
and returns that collection. Nulls and modifiability are as the collection allows.
Type Parameters
Section titled “Type Parameters”T
C extends Collection<T>
Parameters
Section titled “Parameters”collectionFactory
Section titled “collectionFactory”() => C
Returns
Section titled “Returns”Collector<T, C, C>
toConcurrentMap
Section titled “toConcurrentMap”toConcurrentMap: {<
T,K,U>(keyMapper,valueMapper):Collector<T,any,Map<K,U>>; <T,K,U>(keyMapper,valueMapper,mergeFunction):Collector<T,any,Map<K,U>>; <T,K,U,M>(keyMapper,valueMapper,mergeFunction,mapFactory):Collector<T,any,M>; }
Returns a collector with the same results as toMap, reported as CONCURRENT, UNORDERED and
IDENTITY_FINISH. The default map is a HashMap.
Call Signature
Section titled “Call Signature”<
T,K,U>(keyMapper,valueMapper):Collector<T,any,Map<K,U>>
Same results as toMap, reported as CONCURRENT, UNORDERED and IDENTITY_FINISH. Default map: HashMap (null keys are not rejected).
Type Parameters
Section titled “Type Parameters”T
K
U
Parameters
Section titled “Parameters”keyMapper
Section titled “keyMapper”(t) => K
valueMapper
Section titled “valueMapper”(t) => U
Returns
Section titled “Returns”Collector<T, any, Map<K, U>>
Call Signature
Section titled “Call Signature”<
T,K,U>(keyMapper,valueMapper,mergeFunction):Collector<T,any,Map<K,U>>
As toMap(keyMapper, valueMapper, mergeFunction), reported as CONCURRENT, UNORDERED and IDENTITY_FINISH.
Type Parameters
Section titled “Type Parameters”T
K
U
Parameters
Section titled “Parameters”keyMapper
Section titled “keyMapper”(t) => K
valueMapper
Section titled “valueMapper”(t) => U
mergeFunction
Section titled “mergeFunction”(a, b) => U
Returns
Section titled “Returns”Collector<T, any, Map<K, U>>
Call Signature
Section titled “Call Signature”<
T,K,U,M>(keyMapper,valueMapper,mergeFunction,mapFactory):Collector<T,any,M>
As toMap(keyMapper, valueMapper, mergeFunction, mapFactory), reported as CONCURRENT, UNORDERED and IDENTITY_FINISH.
Type Parameters
Section titled “Type Parameters”T
K
U
M extends Map<K, U>
Parameters
Section titled “Parameters”keyMapper
Section titled “keyMapper”(t) => K
valueMapper
Section titled “valueMapper”(t) => U
mergeFunction
Section titled “mergeFunction”(a, b) => U
mapFactory
Section titled “mapFactory”() => M
Returns
Section titled “Returns”Collector<T, any, M>
Throws
Section titled “Throws”IllegalStateException on a duplicate key without mergeFunction
Throws
Section titled “Throws”NullPointerException if a value is null
toList
Section titled “toList”toList: <
T>() =>Collector<T,List<T>,List<T>>
Returns a collector into a new, modifiable ArrayList in encounter order; null elements are allowed.
Type Parameters
Section titled “Type Parameters”T
Returns
Section titled “Returns”Collector<T, List<T>, List<T>>
toMap: {<
T,K,U>(keyMapper,valueMapper):Collector<T,any,Map<K,U>>; <T,K,U>(keyMapper,valueMapper,mergeFunction):Collector<T,any,Map<K,U>>; <T,K,U,M>(keyMapper,valueMapper,mergeFunction,mapFactory):Collector<T,any,M>; }
Returns a collector into a map of keyMapper(e) to valueMapper(e), by default a HashMap. Without
mergeFunction keys must be unique; with it, values of equal keys are combined as merge(old, new) (a null
merge result removes the key). mapFactory chooses the map, for example a LinkedHashMap for encounter order.
Call Signature
Section titled “Call Signature”<
T,K,U>(keyMapper,valueMapper):Collector<T,any,Map<K,U>>
Without mergeFunction: a duplicate key throws IllegalStateException “Duplicate key k (attempted merging values v1 and v2)”; a null value throws NullPointerException. With mergeFunction: values for equal keys are merged (a null value throws NullPointerException, a null merge result removes the key). Default map HashMap.
Type Parameters
Section titled “Type Parameters”T
K
U
Parameters
Section titled “Parameters”keyMapper
Section titled “keyMapper”(t) => K
valueMapper
Section titled “valueMapper”(t) => U
Returns
Section titled “Returns”Collector<T, any, Map<K, U>>
Call Signature
Section titled “Call Signature”<
T,K,U>(keyMapper,valueMapper,mergeFunction):Collector<T,any,Map<K,U>>
Into a HashMap; values of equal keys are combined with mergeFunction(old, new).
Type Parameters
Section titled “Type Parameters”T
K
U
Parameters
Section titled “Parameters”keyMapper
Section titled “keyMapper”(t) => K
valueMapper
Section titled “valueMapper”(t) => U
mergeFunction
Section titled “mergeFunction”(a, b) => U
Returns
Section titled “Returns”Collector<T, any, Map<K, U>>
Call Signature
Section titled “Call Signature”<
T,K,U,M>(keyMapper,valueMapper,mergeFunction,mapFactory):Collector<T,any,M>
Into the map mapFactory() creates; values of equal keys are combined with mergeFunction(old, new).
Type Parameters
Section titled “Type Parameters”T
K
U
M extends Map<K, U>
Parameters
Section titled “Parameters”keyMapper
Section titled “keyMapper”(t) => K
valueMapper
Section titled “valueMapper”(t) => U
mergeFunction
Section titled “mergeFunction”(a, b) => U
mapFactory
Section titled “mapFactory”() => M
Returns
Section titled “Returns”Collector<T, any, M>
Throws
Section titled “Throws”IllegalStateException “Duplicate key k (attempted merging values v1 and v2)” on a duplicate key without mergeFunction
Throws
Section titled “Throws”NullPointerException if a value is null
toSet: <
T>() =>Collector<T,Set<T>,Set<T>>
Returns a collector into a new, modifiable HashSet (duplicates dropped, no defined order); null is allowed.
Type Parameters
Section titled “Type Parameters”T
Returns
Section titled “Returns”Collector<T, Set<T>, Set<T>>
toUnmodifiableList
Section titled “toUnmodifiableList”toUnmodifiableList: <
T>() =>Collector<T,List<T>,List<T>>
Returns a collector into an unmodifiable list in encounter order.
Type Parameters
Section titled “Type Parameters”T
Returns
Section titled “Returns”Collector<T, List<T>, List<T>>
Throws
Section titled “Throws”NullPointerException (from the finisher) if an element is null
toUnmodifiableMap
Section titled “toUnmodifiableMap”toUnmodifiableMap: {<
T,K,U>(keyMapper,valueMapper):Collector<T,any,Map<K,U>>; <T,K,U>(keyMapper,valueMapper,mergeFunction):Collector<T,any,Map<K,U>>; }
Returns a collector like toMap (same duplicate-key rules) whose result is an unmodifiable map.
Call Signature
Section titled “Call Signature”<
T,K,U>(keyMapper,valueMapper):Collector<T,any,Map<K,U>>
Unmodifiable, null-free result; null keys and values throw NullPointerException, duplicates as toMap.
Type Parameters
Section titled “Type Parameters”T
K
U
Parameters
Section titled “Parameters”keyMapper
Section titled “keyMapper”(t) => K
valueMapper
Section titled “valueMapper”(t) => U
Returns
Section titled “Returns”Collector<T, any, Map<K, U>>
Call Signature
Section titled “Call Signature”<
T,K,U>(keyMapper,valueMapper,mergeFunction):Collector<T,any,Map<K,U>>
As the two-argument form; values of equal keys are combined with mergeFunction(old, new).
Type Parameters
Section titled “Type Parameters”T
K
U
Parameters
Section titled “Parameters”keyMapper
Section titled “keyMapper”(t) => K
valueMapper
Section titled “valueMapper”(t) => U
mergeFunction
Section titled “mergeFunction”(a, b) => U
Returns
Section titled “Returns”Collector<T, any, Map<K, U>>
Throws
Section titled “Throws”IllegalStateException on a duplicate key without mergeFunction
Throws
Section titled “Throws”NullPointerException if a key or value is null, or keyMapper, valueMapper or a given mergeFunction is null
toUnmodifiableSet
Section titled “toUnmodifiableSet”toUnmodifiableSet: <
T>() =>Collector<T,Set<T>,Set<T>>
Returns a collector into an unmodifiable set; duplicates are dropped.
Type Parameters
Section titled “Type Parameters”T
Returns
Section titled “Returns”Collector<T, Set<T>, Set<T>>
Throws
Section titled “Throws”NullPointerException (from the finisher) if an element is null