public final class Collectors extends Object
Collector that implement various useful reduction operations, such as accumulating elements into collections, summarizing elements according to various criteria, etc.
The following are examples of using the predefined collectors to perform common mutable reduction tasks:
// Accumulate names into a List List<String> list = people.stream().map(Person::getName).collect(Collectors.toList()); // Accumulate names into a TreeSet Set<String> set = people.stream().map(Person::getName).collect(Collectors.toCollection(TreeSet::new)); // Convert elements to strings and concatenate them, separated by commas String joined = things.stream() .map(Object::toString) .collect(Collectors.joining(", ")); // Compute sum of salaries of employee int total = employees.stream() .collect(Collectors.summingInt(Employee::getSalary))); // Group employees by department Map<Department, List<Employee>> byDept = employees.stream() .collect(Collectors.groupingBy(Employee::getDepartment)); // Compute sum of salaries by department Map<Department, Integer> totalByDept = employees.stream() .collect(Collectors.groupingBy(Employee::getDepartment, Collectors.summingInt(Employee::getSalary))); // Partition students into passing and failing Map<Boolean, List<Student>> passingFailing = students.stream() .collect(Collectors.partitioningBy(s -> s.getGrade() >= PASS_THRESHOLD));
| Modifier and Type | Method and Description |
|---|---|
static <T> Collector |
averagingDouble(ToDoubleFunction
Returns a
Collector that produces the arithmetic mean of a double-valued function applied to the input elements.
|
static <T> Collector |
averagingInt(ToIntFunction
Returns a
Collector that produces the arithmetic mean of an integer-valued function applied to the input elements.
|
static <T> Collector |
averagingLong(ToLongFunction
Returns a
Collector that produces the arithmetic mean of a long-valued function applied to the input elements.
|
static <T |
collectingAndThen(Collector
Adapts a
Collector to perform an additional finishing transformation.
|
static <T> Collector |
counting()
Returns a
Collector accepting elements of type
T that counts the number of input elements.
|
static <T |
groupingBy(Function
Returns a
Collector implementing a "group by" operation on input elements of type
T, grouping elements according to a classification function, and returning the results in a
Map.
|
static <T |
groupingBy(Function
Returns a
Collector implementing a cascaded "group by" operation on input elements of type
T, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstream
Collector.
|
static <T |
groupingBy(Function
Returns a
Collector implementing a cascaded "group by" operation on input elements of type
T, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstream
Collector.
|
static <T |
groupingByConcurrent(Function
Returns a concurrent
Collector implementing a "group by" operation on input elements of type
T, grouping elements according to a classification function.
|
static <T |
groupingByConcurrent(Function
Returns a concurrent
Collector implementing a cascaded "group by" operation on input elements of type
T, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstream
Collector.
|
static <T |
groupingByConcurrent(Function
Returns a concurrent
Collector implementing a cascaded "group by" operation on input elements of type
T, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstream
Collector.
|
static Collector |
joining()
Returns a
Collector that concatenates the input elements into a
String, in encounter order.
|
static Collector |
joining(CharSequence
Returns a
Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.
|
static Collector |
joining(CharSequence
Returns a
Collector that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.
|
static <T |
mapping(Function
Adapts a
Collector accepting elements of type
U to one accepting elements of type
T by applying a mapping function to each input element before accumulation.
|
static <T> Collector |
maxBy(Comparator
Returns a
Collector that produces the maximal element according to a given
Comparator, described as an
Optional<T>.
|
static <T> Collector |
minBy(Comparator
Returns a
Collector that produces the minimal element according to a given
Comparator, described as an
Optional<T>.
|
static <T> Collector |
partitioningBy(Predicate
Returns a
Collector which partitions the input elements according to a
Predicate, and organizes them into a
Map<Boolean, List<T>>.
|
static <T |
partitioningBy(Predicate
Returns a
Collector which partitions the input elements according to a
Predicate, reduces the values in each partition according to another
Collector, and organizes them into a
Map<Boolean, D> whose values are the result of the downstream reduction.
|
static <T> Collector |
reducing(BinaryOperator
Returns a
Collector which performs a reduction of its input elements under a specified
BinaryOperator.
|
static <T> Collector |
reducing(T identity, BinaryOperator
Returns a
Collector which performs a reduction of its input elements under a specified
BinaryOperator using the provided identity.
|
static <T |
reducing(U identity, Function
Returns a
Collector which performs a reduction of its input elements under a specified mapping function and
BinaryOperator.
|
static <T> Collector |
summarizingDouble(ToDoubleFunction
Returns a
Collector which applies an
double-producing mapping function to each input element, and returns summary statistics for the resulting values.
|
static <T> Collector |
summarizingInt(ToIntFunction
Returns a
Collector which applies an
int-producing mapping function to each input element, and returns summary statistics for the resulting values.
|
static <T> Collector |
summarizingLong(ToLongFunction
Returns a
Collector which applies an
long-producing mapping function to each input element, and returns summary statistics for the resulting values.
|
static <T> Collector |
summingDouble(ToDoubleFunction
Returns a
Collector that produces the sum of a double-valued function applied to the input elements.
|
static <T> Collector |
summingInt(ToIntFunction
Returns a
Collector that produces the sum of a integer-valued function applied to the input elements.
|
static <T> Collector |
summingLong(ToLongFunction
Returns a
Collector that produces the sum of a long-valued function applied to the input elements.
|
static <T |
toCollection(Supplier
Returns a
Collector that accumulates the input elements into a new
Collection, in encounter order.
|
static <T |
toConcurrentMap(Function
Returns a concurrent
Collector that accumulates elements into a
ConcurrentMap whose keys and values are the result of applying the provided mapping functions to the input elements.
|
static <T |
toConcurrentMap(Function
Returns a concurrent
Collector that accumulates elements into a
ConcurrentMap whose keys and values are the result of applying the provided mapping functions to the input elements.
|
static <T |
toConcurrentMap(Function
Returns a concurrent
Collector that accumulates elements into a
ConcurrentMap whose keys and values are the result of applying the provided mapping functions to the input elements.
|
static <T> Collector |
toList()
Returns a
Collector that accumulates the input elements into a new
List.
|
static <T |
toMap(Function
Returns a
Collector that accumulates elements into a
Map whose keys and values are the result of applying the provided mapping functions to the input elements.
|
static <T |
toMap(Function
Returns a
Collector that accumulates elements into a
Map whose keys and values are the result of applying the provided mapping functions to the input elements.
|
static <T |
toMap(Function
Returns a
Collector that accumulates elements into a
Map whose keys and values are the result of applying the provided mapping functions to the input elements.
|
static <T> Collector |
toSet()
Returns a
Collector that accumulates the input elements into a new
Set.
|
public static <T,C extends Collection <T>> Collector <T ,? ,C> toCollection(Supplier <C> collectionFactory)
Collector that accumulates the input elements into a new
Collection, in encounter order. The
Collection is created by the provided factory.
T - the type of the input elements
C - the type of the resulting
Collection
collectionFactory - a
Supplier which returns a new, empty
Collection of the appropriate type
Collector which collects all the input elements into a
Collection, in encounter order
public static <T> Collector<T ,? ,List <T>> toList()
Collector that accumulates the input elements into a new
List. There are no guarantees on the type, mutability, serializability, or thread-safety of the
List returned; if more control over the returned
List is required, use
toCollection(Supplier).
T - the type of the input elements
Collector which collects all the input elements into a
List, in encounter order
public static <T> Collector<T ,? ,Set <T>> toSet()
Collector that accumulates the input elements into a new
Set. There are no guarantees on the type, mutability, serializability, or thread-safety of the
Set returned; if more control over the returned
Set is required, use
toCollection(Supplier).
This is an unordered Collector.
T - the type of the input elements
Collector which collects all the input elements into a
Set
public static Collector<CharSequence ,? ,String > joining()
Collector that concatenates the input elements into a
String, in encounter order.
Collector that concatenates the input elements into a
String, in encounter order
public static Collector<CharSequence ,? ,String > joining(CharSequence delimiter)
Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.
delimiter - the delimiter to be used between each element
Collector which concatenates CharSequence elements, separated by the specified delimiter, in encounter order
public static Collector<CharSequence ,? ,String > joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
Collector that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.
delimiter - the delimiter to be used between each element
prefix - the sequence of characters to be used at the beginning of the joined result
suffix - the sequence of characters to be used at the end of the joined result
Collector which concatenates CharSequence elements, separated by the specified delimiter, in encounter order
public static <T,U ,A ,R> Collector <T ,? ,R> mapping(Function <? super T ,? extends U> mapper, Collector <? super U ,A ,R> downstream)
Collector accepting elements of type
U to one accepting elements of type
T by applying a mapping function to each input element before accumulation.
T - the type of the input elements
U - type of elements accepted by downstream collector
A - intermediate accumulation type of the downstream collector
R - result type of collector
mapper - a function to be applied to the input elements
downstream - a collector which will accept mapped values
public static <T,A ,R ,RR> Collector <T ,A ,RR> collectingAndThen(Collector <T ,A ,R> downstream, Function <R ,RR> finisher)
Collector to perform an additional finishing transformation. For example, one could adapt the
toList() collector to always produce an immutable list with:
List<String> people = people.stream().collect(collectingAndThen(toList(), Collections::unmodifiableList));
T - the type of the input elements
A - intermediate accumulation type of the downstream collector
R - result type of the downstream collector
RR - result type of the resulting collector
downstream - a collector
finisher - a function to be applied to the final result of the downstream collector
public static <T> Collector<T ,? ,Long > counting()
Collector accepting elements of type
T that counts the number of input elements. If no elements are present, the result is 0.
T - the type of the input elements
Collector that counts the input elements
public static <T> Collector<T ,? ,Optional <T>> minBy(Comparator <? super T> comparator)
Collector that produces the minimal element according to a given
Comparator, described as an
Optional<T>.
T - the type of the input elements
comparator - a
Comparator for comparing elements
Collector that produces the minimal value
public static <T> Collector<T ,? ,Optional <T>> maxBy(Comparator <? super T> comparator)
Collector that produces the maximal element according to a given
Comparator, described as an
Optional<T>.
T - the type of the input elements
comparator - a
Comparator for comparing elements
Collector that produces the maximal value
public static <T> Collector<T ,? ,Integer > summingInt(ToIntFunction <? super T> mapper)
Collector that produces the sum of a integer-valued function applied to the input elements. If no elements are present, the result is 0.
T - the type of the input elements
mapper - a function extracting the property to be summed
Collector that produces the sum of a derived property
public static <T> Collector<T ,? ,Long > summingLong(ToLongFunction <? super T> mapper)
Collector that produces the sum of a long-valued function applied to the input elements. If no elements are present, the result is 0.
T - the type of the input elements
mapper - a function extracting the property to be summed
Collector that produces the sum of a derived property
public static <T> Collector<T ,? ,Double > summingDouble(ToDoubleFunction <? super T> mapper)
Collector that produces the sum of a double-valued function applied to the input elements. If no elements are present, the result is 0.
The sum returned can vary depending upon the order in which values are recorded, due to accumulated rounding error in addition of values of differing magnitudes. Values sorted by increasing absolute magnitude tend to yield more accurate results. If any recorded value is a NaN or the sum is at any point a NaN then the sum will be NaN.
T - the type of the input elements
mapper - a function extracting the property to be summed
Collector that produces the sum of a derived property
public static <T> Collector<T ,? ,Double > averagingInt(ToIntFunction <? super T> mapper)
Collector that produces the arithmetic mean of an integer-valued function applied to the input elements. If no elements are present, the result is 0.
T - the type of the input elements
mapper - a function extracting the property to be summed
Collector that produces the sum of a derived property
public static <T> Collector<T ,? ,Double > averagingLong(ToLongFunction <? super T> mapper)
Collector that produces the arithmetic mean of a long-valued function applied to the input elements. If no elements are present, the result is 0.
T - the type of the input elements
mapper - a function extracting the property to be summed
Collector that produces the sum of a derived property
public static <T> Collector<T ,? ,Double > averagingDouble(ToDoubleFunction <? super T> mapper)
Collector that produces the arithmetic mean of a double-valued function applied to the input elements. If no elements are present, the result is 0.
The average returned can vary depending upon the order in which values are recorded, due to accumulated rounding error in addition of values of differing magnitudes. Values sorted by increasing absolute magnitude tend to yield more accurate results. If any recorded value is a NaN or the sum is at any point a NaN then the average will be NaN.
T - the type of the input elements
mapper - a function extracting the property to be summed
Collector that produces the sum of a derived property
public static <T> Collector<T ,? ,T> reducing(T identity, BinaryOperator <T> op)
Collector which performs a reduction of its input elements under a specified
BinaryOperator using the provided identity.
T - element type for the input and output of the reduction
identity - the identity value for the reduction (also, the value that is returned when there are no input elements)
op - a
BinaryOperator<T> used to reduce the input elements
Collector which implements the reduction operation
reducing(BinaryOperator),
reducing(Object, Function, BinaryOperator)
public static <T> Collector<T ,? ,Optional <T>> reducing(BinaryOperator <T> op)
Collector which performs a reduction of its input elements under a specified
BinaryOperator. The result is described as an
Optional<T>.
T - element type for the input and output of the reduction
op - a
BinaryOperator<T> used to reduce the input elements
Collector which implements the reduction operation
reducing(Object, BinaryOperator),
reducing(Object, Function, BinaryOperator)
public static <T,U> Collector <T ,? ,U> reducing(U identity, Function <? super T ,? extends U> mapper, BinaryOperator <U> op)
Collector which performs a reduction of its input elements under a specified mapping function and
BinaryOperator. This is a generalization of
reducing(Object, BinaryOperator) which allows a transformation of the elements before reduction.
T - the type of the input elements
U - the type of the mapped values
identity - the identity value for the reduction (also, the value that is returned when there are no input elements)
mapper - a mapping function to apply to each input value
op - a
BinaryOperator<U> used to reduce the mapped values
Collector implementing the map-reduce operation
reducing(Object, BinaryOperator),
reducing(BinaryOperator)
public static <T,K> Collector <T ,? ,Map <K ,List <T>>> groupingBy(Function <? super T ,? extends K> classifier)
Collector implementing a "group by" operation on input elements of type
T, grouping elements according to a classification function, and returning the results in a
Map.
The classification function maps elements to some key type K. The collector produces a Map<K, List<T>> whose keys are the values resulting from applying the classification function to the input elements, and whose corresponding values are Lists containing the input elements which map to the associated key under the classification function.
There are no guarantees on the type, mutability, serializability, or thread-safety of the Map or List objects returned.
T - the type of the input elements
K - the type of the keys
classifier - the classifier function mapping input elements to keys
Collector implementing the group-by operation
groupingBy(Function, Collector),
groupingBy(Function, Supplier, Collector),
groupingByConcurrent(Function)
public static <T,K ,A ,D> Collector <T ,? ,Map <K ,D>> groupingBy(Function <? super T ,? extends K> classifier, Collector <? super T ,A ,D> downstream)
Collector implementing a cascaded "group by" operation on input elements of type
T, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstream
Collector.
The classification function maps elements to some key type K. The downstream collector operates on elements of type T and produces a result of type D. The resulting collector produces a Map<K, D>.
There are no guarantees on the type, mutability, serializability, or thread-safety of the Map returned.
For example, to compute the set of last names of people in each city:
Map<City, Set<String>> namesByCity = people.stream().collect(groupingBy(Person::getCity, mapping(Person::getLastName, toSet())));
T - the type of the input elements
K - the type of the keys
A - the intermediate accumulation type of the downstream collector
D - the result type of the downstream reduction
classifier - a classifier function mapping input elements to keys
downstream - a
Collector implementing the downstream reduction
Collector implementing the cascaded group-by operation
groupingBy(Function),
groupingBy(Function, Supplier, Collector),
groupingByConcurrent(Function, Collector)
public static <T,K ,D ,A ,M extends Map <K ,D>> Collector <T ,? ,M> groupingBy(Function <? super T ,? extends K> classifier, Supplier <M> mapFactory, Collector <? super T ,A ,D> downstream)
Collector implementing a cascaded "group by" operation on input elements of type
T, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstream
Collector. The
Map produced by the Collector is created with the supplied factory function.
The classification function maps elements to some key type K. The downstream collector operates on elements of type T and produces a result of type D. The resulting collector produces a Map<K, D>.
For example, to compute the set of last names of people in each city, where the city names are sorted:
Map<City, Set<String>> namesByCity = people.stream().collect(groupingBy(Person::getCity, TreeMap::new, mapping(Person::getLastName, toSet())));
T - the type of the input elements
K - the type of the keys
A - the intermediate accumulation type of the downstream collector
D - the result type of the downstream reduction
M - the type of the resulting
Map
classifier - a classifier function mapping input elements to keys
downstream - a
Collector implementing the downstream reduction
mapFactory - a function which, when called, produces a new empty
Map of the desired type
Collector implementing the cascaded group-by operation
groupingBy(Function, Collector),
groupingBy(Function),
groupingByConcurrent(Function, Supplier, Collector)
public static <T,K> Collector <T ,? ,ConcurrentMap <K ,List <T>>> groupingByConcurrent(Function <? super T ,? extends K> classifier)
Collector implementing a "group by" operation on input elements of type
T, grouping elements according to a classification function.
This is a concurrent and unordered Collector.
The classification function maps elements to some key type K. The collector produces a ConcurrentMap<K, List<T>> whose keys are the values resulting from applying the classification function to the input elements, and whose corresponding values are Lists containing the input elements which map to the associated key under the classification function.
There are no guarantees on the type, mutability, or serializability of the Map or List objects returned, or of the thread-safety of the List objects returned.
T - the type of the input elements
K - the type of the keys
classifier - a classifier function mapping input elements to keys
Collector implementing the group-by operation
groupingBy(Function),
groupingByConcurrent(Function, Collector),
groupingByConcurrent(Function, Supplier, Collector)
public static <T,K ,A ,D> Collector <T ,? ,ConcurrentMap <K ,D>> groupingByConcurrent(Function <? super T ,? extends K> classifier, Collector <? super T ,A ,D> downstream)
Collector implementing a cascaded "group by" operation on input elements of type
T, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstream
Collector.
This is a concurrent and unordered Collector.
The classification function maps elements to some key type K. The downstream collector operates on elements of type T and produces a result of type D. The resulting collector produces a Map<K, D>.
For example, to compute the set of last names of people in each city, where the city names are sorted:
ConcurrentMap<City, Set<String>> namesByCity = people.stream().collect(groupingByConcurrent(Person::getCity, mapping(Person::getLastName, toSet())));
T - the type of the input elements
K - the type of the keys
A - the intermediate accumulation type of the downstream collector
D - the result type of the downstream reduction
classifier - a classifier function mapping input elements to keys
downstream - a
Collector implementing the downstream reduction
Collector implementing the cascaded group-by operation
groupingBy(Function, Collector),
groupingByConcurrent(Function),
groupingByConcurrent(Function, Supplier, Collector)
public static <T,K ,A ,D ,M extends ConcurrentMap <K ,D>> Collector <T ,? ,M> groupingByConcurrent(Function <? super T ,? extends K> classifier, Supplier <M> mapFactory, Collector <? super T ,A ,D> downstream)
Collector implementing a cascaded "group by" operation on input elements of type
T, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstream
Collector. The
ConcurrentMap produced by the Collector is created with the supplied factory function.
This is a concurrent and unordered Collector.
The classification function maps elements to some key type K. The downstream collector operates on elements of type T and produces a result of type D. The resulting collector produces a Map<K, D>.
For example, to compute the set of last names of people in each city, where the city names are sorted:
ConcurrentMap<City, Set<String>> namesByCity = people.stream().collect(groupingBy(Person::getCity, ConcurrentSkipListMap::new, mapping(Person::getLastName, toSet())));
T - the type of the input elements
K - the type of the keys
A - the intermediate accumulation type of the downstream collector
D - the result type of the downstream reduction
M - the type of the resulting
ConcurrentMap
classifier - a classifier function mapping input elements to keys
downstream - a
Collector implementing the downstream reduction
mapFactory - a function which, when called, produces a new empty
ConcurrentMap of the desired type
Collector implementing the cascaded group-by operation
groupingByConcurrent(Function),
groupingByConcurrent(Function, Collector),
groupingBy(Function, Supplier, Collector)
public static <T> Collector<T ,? ,Map <Boolean ,List <T>>> partitioningBy(Predicate <? super T> predicate)
Collector which partitions the input elements according to a
Predicate, and organizes them into a
Map<Boolean, List<T>>. There are no guarantees on the type, mutability, serializability, or thread-safety of the
Map returned.
T - the type of the input elements
predicate - a predicate used for classifying input elements
Collector implementing the partitioning operation
partitioningBy(Predicate, Collector)
public static <T,D ,A> Collector <T ,? ,Map <Boolean ,D>> partitioningBy(Predicate <? super T> predicate, Collector <? super T ,A ,D> downstream)
Collector which partitions the input elements according to a
Predicate, reduces the values in each partition according to another
Collector, and organizes them into a
Map<Boolean, D> whose values are the result of the downstream reduction.
There are no guarantees on the type, mutability, serializability, or thread-safety of the Map returned.
T - the type of the input elements
A - the intermediate accumulation type of the downstream collector
D - the result type of the downstream reduction
predicate - a predicate used for classifying input elements
downstream - a
Collector implementing the downstream reduction
Collector implementing the cascaded partitioning operation
partitioningBy(Predicate)
public static <T,K ,U> Collector <T ,? ,Map <K ,U>> toMap(Function <? super T ,? extends K> keyMapper, Function <? super T ,? extends U> valueMapper)
Collector that accumulates elements into a
Map whose keys and values are the result of applying the provided mapping functions to the input elements.
If the mapped keys contains duplicates (according to Object), an IllegalStateException is thrown when the collection operation is performed. If the mapped keys may have duplicates, use toMap(Function, Function, BinaryOperator) instead.
T - the type of the input elements
K - the output type of the key mapping function
U - the output type of the value mapping function
keyMapper - a mapping function to produce keys
valueMapper - a mapping function to produce values
Collector which collects elements into a
Map whose keys and values are the result of applying mapping functions to the input elements
toMap(Function, Function, BinaryOperator),
toMap(Function, Function, BinaryOperator, Supplier),
toConcurrentMap(Function, Function)
public static <T,K ,U> Collector <T ,? ,Map <K ,U>> toMap(Function <? super T ,? extends K> keyMapper, Function <? super T ,? extends U> valueMapper, BinaryOperator <U> mergeFunction)
Collector that accumulates elements into a
Map whose keys and values are the result of applying the provided mapping functions to the input elements.
If the mapped keys contains duplicates (according to Object), the value mapping function is applied to each equal element, and the results are merged using the provided merging function.
T - the type of the input elements
K - the output type of the key mapping function
U - the output type of the value mapping function
keyMapper - a mapping function to produce keys
valueMapper - a mapping function to produce values
mergeFunction - a merge function, used to resolve collisions between values associated with the same key, as supplied to
Map.merge(Object, Object, BiFunction)
Collector which collects elements into a
Map whose keys are the result of applying a key mapping function to the input elements, and whose values are the result of applying a value mapping function to all input elements equal to the key and combining them using the merge function
toMap(Function, Function),
toMap(Function, Function, BinaryOperator, Supplier),
toConcurrentMap(Function, Function, BinaryOperator)
public static <T,K ,U ,M extends Map <K ,U>> Collector <T ,? ,M> toMap(Function <? super T ,? extends K> keyMapper, Function <? super T ,? extends U> valueMapper, BinaryOperator <U> mergeFunction, Supplier <M> mapSupplier)
Collector that accumulates elements into a
Map whose keys and values are the result of applying the provided mapping functions to the input elements.
If the mapped keys contains duplicates (according to Object), the value mapping function is applied to each equal element, and the results are merged using the provided merging function. The Map is created by a provided supplier function.
T - the type of the input elements
K - the output type of the key mapping function
U - the output type of the value mapping function
M - the type of the resulting
Map
keyMapper - a mapping function to produce keys
valueMapper - a mapping function to produce values
mergeFunction - a merge function, used to resolve collisions between values associated with the same key, as supplied to
Map.merge(Object, Object, BiFunction)
mapSupplier - a function which returns a new, empty
Map into which the results will be inserted
Collector which collects elements into a
Map whose keys are the result of applying a key mapping function to the input elements, and whose values are the result of applying a value mapping function to all input elements equal to the key and combining them using the merge function
toMap(Function, Function),
toMap(Function, Function, BinaryOperator),
toConcurrentMap(Function, Function, BinaryOperator, Supplier)
public static <T,K ,U> Collector <T ,? ,ConcurrentMap <K ,U>> toConcurrentMap(Function <? super T ,? extends K> keyMapper, Function <? super T ,? extends U> valueMapper)
Collector that accumulates elements into a
ConcurrentMap whose keys and values are the result of applying the provided mapping functions to the input elements.
If the mapped keys contains duplicates (according to Object), an IllegalStateException is thrown when the collection operation is performed. If the mapped keys may have duplicates, use toConcurrentMap(Function, Function, BinaryOperator) instead.
T - the type of the input elements
K - the output type of the key mapping function
U - the output type of the value mapping function
keyMapper - the mapping function to produce keys
valueMapper - the mapping function to produce values
Collector which collects elements into a
ConcurrentMap whose keys are the result of applying a key mapping function to the input elements, and whose values are the result of applying a value mapping function to the input elements
toMap(Function, Function),
toConcurrentMap(Function, Function, BinaryOperator),
toConcurrentMap(Function, Function, BinaryOperator, Supplier)
public static <T,K ,U> Collector <T ,? ,ConcurrentMap <K ,U>> toConcurrentMap(Function <? super T ,? extends K> keyMapper, Function <? super T ,? extends U> valueMapper, BinaryOperator <U> mergeFunction)
Collector that accumulates elements into a
ConcurrentMap whose keys and values are the result of applying the provided mapping functions to the input elements.
If the mapped keys contains duplicates (according to Object), the value mapping function is applied to each equal element, and the results are merged using the provided merging function.
T - the type of the input elements
K - the output type of the key mapping function
U - the output type of the value mapping function
keyMapper - a mapping function to produce keys
valueMapper - a mapping function to produce values
mergeFunction - a merge function, used to resolve collisions between values associated with the same key, as supplied to
Map.merge(Object, Object, BiFunction)
Collector which collects elements into a
ConcurrentMap whose keys are the result of applying a key mapping function to the input elements, and whose values are the result of applying a value mapping function to all input elements equal to the key and combining them using the merge function
toConcurrentMap(Function, Function),
toConcurrentMap(Function, Function, BinaryOperator, Supplier),
toMap(Function, Function, BinaryOperator)
public static <T,K ,U ,M extends ConcurrentMap <K ,U>> Collector <T ,? ,M> toConcurrentMap(Function <? super T ,? extends K> keyMapper, Function <? super T ,? extends U> valueMapper, BinaryOperator <U> mergeFunction, Supplier <M> mapSupplier)
Collector that accumulates elements into a
ConcurrentMap whose keys and values are the result of applying the provided mapping functions to the input elements.
If the mapped keys contains duplicates (according to Object), the value mapping function is applied to each equal element, and the results are merged using the provided merging function. The ConcurrentMap is created by a provided supplier function.
This is a concurrent and unordered Collector.
T - the type of the input elements
K - the output type of the key mapping function
U - the output type of the value mapping function
M - the type of the resulting
ConcurrentMap
keyMapper - a mapping function to produce keys
valueMapper - a mapping function to produce values
mergeFunction - a merge function, used to resolve collisions between values associated with the same key, as supplied to
Map.merge(Object, Object, BiFunction)
mapSupplier - a function which returns a new, empty
Map into which the results will be inserted
Collector which collects elements into a
ConcurrentMap whose keys are the result of applying a key mapping function to the input elements, and whose values are the result of applying a value mapping function to all input elements equal to the key and combining them using the merge function
toConcurrentMap(Function, Function),
toConcurrentMap(Function, Function, BinaryOperator),
toMap(Function, Function, BinaryOperator, Supplier)
public static <T> Collector<T ,? ,IntSummaryStatistics > summarizingInt(ToIntFunction <? super T> mapper)
Collector which applies an
int-producing mapping function to each input element, and returns summary statistics for the resulting values.
T - the type of the input elements
mapper - a mapping function to apply to each element
Collector implementing the summary-statistics reduction
summarizingDouble(ToDoubleFunction),
summarizingLong(ToLongFunction)
public static <T> Collector<T ,? ,LongSummaryStatistics > summarizingLong(ToLongFunction <? super T> mapper)
Collector which applies an
long-producing mapping function to each input element, and returns summary statistics for the resulting values.
T - the type of the input elements
mapper - the mapping function to apply to each element
Collector implementing the summary-statistics reduction
summarizingDouble(ToDoubleFunction),
summarizingInt(ToIntFunction)
public static <T> Collector<T ,? ,DoubleSummaryStatistics > summarizingDouble(ToDoubleFunction <? super T> mapper)
Collector which applies an
double-producing mapping function to each input element, and returns summary statistics for the resulting values.
T - the type of the input elements
mapper - a mapping function to apply to each element
Collector implementing the summary-statistics reduction
summarizingLong(ToLongFunction),
summarizingInt(ToIntFunction)