- java.lang.Object
- 
- java.util.stream.Collectors
 
- 
 public final class Collectors extends Object Implementations ofCollectorthat 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));- Since:
- 1.8
 
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Collector<T,?,Double>averagingDouble(ToDoubleFunction<? super T> mapper)Returns aCollectorthat produces the arithmetic mean of a double-valued function applied to the input elements.static <T> Collector<T,?,Double>averagingInt(ToIntFunction<? super T> mapper)Returns aCollectorthat produces the arithmetic mean of an integer-valued function applied to the input elements.static <T> Collector<T,?,Double>averagingLong(ToLongFunction<? super T> mapper)Returns aCollectorthat produces the arithmetic mean of a long-valued function applied to the input elements.static <T,A,R,RR>
 Collector<T,A,RR>collectingAndThen(Collector<T,A,R> downstream, Function<R,RR> finisher)Adapts aCollectorto perform an additional finishing transformation.static <T> Collector<T,?,Long>counting()Returns aCollectoraccepting elements of typeTthat counts the number of input elements.static <T,A,R>
 Collector<T,?,R>filtering(Predicate<? super T> predicate, Collector<? super T,A,R> downstream)Adapts aCollectorto one accepting elements of the same typeTby applying the predicate to each input element and only accumulating if the predicate returnstrue.static <T,U,A,R>
 Collector<T,?,R>flatMapping(Function<? super T,? extends Stream<? extends U>> mapper, Collector<? super U,A,R> downstream)Adapts aCollectoraccepting elements of typeUto one accepting elements of typeTby applying a flat mapping function to each input element before accumulation.static <T,K>
 Collector<T,?,Map<K,List<T>>>groupingBy(Function<? super T,? extends K> classifier)Returns aCollectorimplementing a "group by" operation on input elements of typeT, grouping elements according to a classification function, and returning the results in aMap.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)Returns aCollectorimplementing 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,?,Map<K,D>>groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)Returns aCollectorimplementing 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>>>groupingByConcurrent(Function<? super T,? extends K> classifier)Returns a concurrentCollectorimplementing 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>groupingByConcurrent(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)Returns a concurrentCollectorimplementing 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>>groupingByConcurrent(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream)Returns a concurrentCollectorimplementing 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>joining()Returns aCollectorthat concatenates the input elements into aString, in encounter order.static Collector<CharSequence,?,String>joining(CharSequence delimiter)Returns aCollectorthat concatenates the input elements, separated by the specified delimiter, in encounter order.static Collector<CharSequence,?,String>joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)Returns aCollectorthat 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>mapping(Function<? super T,? extends U> mapper, Collector<? super U,A,R> downstream)Adapts aCollectoraccepting elements of typeUto one accepting elements of typeTby applying a mapping function to each input element before accumulation.static <T> Collector<T,?,Optional<T>>maxBy(Comparator<? super T> comparator)Returns aCollectorthat produces the maximal element according to a givenComparator, described as anOptional<T>.static <T> Collector<T,?,Optional<T>>minBy(Comparator<? super T> comparator)Returns aCollectorthat produces the minimal element according to a givenComparator, described as anOptional<T>.static <T> Collector<T,?,Map<Boolean,List<T>>>partitioningBy(Predicate<? super T> predicate)Returns aCollectorwhich partitions the input elements according to aPredicate, and organizes them into aMap<Boolean, List<T>>.static <T,D,A>
 Collector<T,?,Map<Boolean,D>>partitioningBy(Predicate<? super T> predicate, Collector<? super T,A,D> downstream)Returns aCollectorwhich 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> Collector<T,?,Optional<T>>reducing(BinaryOperator<T> op)Returns aCollectorwhich performs a reduction of its input elements under a specifiedBinaryOperator.static <T> Collector<T,?,T>reducing(T identity, BinaryOperator<T> op)Returns aCollectorwhich performs a reduction of its input elements under a specifiedBinaryOperatorusing the provided identity.static <T,U>
 Collector<T,?,U>reducing(U identity, Function<? super T,? extends U> mapper, BinaryOperator<U> op)Returns aCollectorwhich performs a reduction of its input elements under a specified mapping function andBinaryOperator.static <T> Collector<T,?,DoubleSummaryStatistics>summarizingDouble(ToDoubleFunction<? super T> mapper)Returns aCollectorwhich applies andouble-producing mapping function to each input element, and returns summary statistics for the resulting values.static <T> Collector<T,?,IntSummaryStatistics>summarizingInt(ToIntFunction<? super T> mapper)Returns aCollectorwhich applies anint-producing mapping function to each input element, and returns summary statistics for the resulting values.static <T> Collector<T,?,LongSummaryStatistics>summarizingLong(ToLongFunction<? super T> mapper)Returns aCollectorwhich applies anlong-producing mapping function to each input element, and returns summary statistics for the resulting values.static <T> Collector<T,?,Double>summingDouble(ToDoubleFunction<? super T> mapper)Returns aCollectorthat produces the sum of a double-valued function applied to the input elements.static <T> Collector<T,?,Integer>summingInt(ToIntFunction<? super T> mapper)Returns aCollectorthat produces the sum of a integer-valued function applied to the input elements.static <T> Collector<T,?,Long>summingLong(ToLongFunction<? super T> mapper)Returns aCollectorthat produces the sum of a long-valued function applied to the input elements.static <T,C extends Collection<T>>
 Collector<T,?,C>toCollection(Supplier<C> collectionFactory)Returns aCollectorthat accumulates the input elements into a newCollection, in encounter order.static <T,K,U>
 Collector<T,?,ConcurrentMap<K,U>>toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)Returns a concurrentCollectorthat accumulates elements into aConcurrentMapwhose 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>>toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)Returns a concurrentCollectorthat accumulates elements into aConcurrentMapwhose 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>toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapFactory)Returns a concurrentCollectorthat accumulates elements into aConcurrentMapwhose keys and values are the result of applying the provided mapping functions to the input elements.static <T> Collector<T,?,List<T>>toList()Returns aCollectorthat accumulates the input elements into a newList.static <T,K,U>
 Collector<T,?,Map<K,U>>toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)Returns aCollectorthat accumulates elements into aMapwhose keys and values are the result of applying the provided mapping functions to the input elements.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)Returns aCollectorthat accumulates elements into aMapwhose keys and values are the result of applying the provided mapping functions to the input elements.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> mapFactory)Returns aCollectorthat accumulates elements into aMapwhose keys and values are the result of applying the provided mapping functions to the input elements.static <T> Collector<T,?,Set<T>>toSet()Returns aCollectorthat accumulates the input elements into a newSet.static <T> Collector<T,?,List<T>>toUnmodifiableList()Returns aCollectorthat accumulates the input elements into an unmodifiable List in encounter order.static <T,K,U>
 Collector<T,?,Map<K,U>>toUnmodifiableMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)Returns aCollectorthat 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.static <T,K,U>
 Collector<T,?,Map<K,U>>toUnmodifiableMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction)Returns aCollectorthat 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.static <T> Collector<T,?,Set<T>>toUnmodifiableSet()Returns aCollectorthat accumulates the input elements into an unmodifiable Set.
 
- 
- 
- 
Method Detail- 
toCollectionpublic static <T,C extends Collection<T>> Collector<T,?,C> toCollection(Supplier<C> collectionFactory) Returns aCollectorthat accumulates the input elements into a newCollection, in encounter order. TheCollectionis created by the provided factory.- Type Parameters:
- T- the type of the input elements
- C- the type of the resulting- Collection
- Parameters:
- collectionFactory- a supplier providing a new empty- Collectioninto which the results will be inserted
- Returns:
- a Collectorwhich collects all the input elements into aCollection, in encounter order
 
 - 
toListpublic static <T> Collector<T,?,List<T>> toList() Returns aCollectorthat accumulates the input elements into a newList. There are no guarantees on the type, mutability, serializability, or thread-safety of theListreturned; if more control over the returnedListis required, usetoCollection(Supplier).- Type Parameters:
- T- the type of the input elements
- Returns:
- a Collectorwhich collects all the input elements into aList, in encounter order
 
 - 
toUnmodifiableListpublic static <T> Collector<T,?,List<T>> toUnmodifiableList() Returns aCollectorthat accumulates the input elements into an unmodifiable List in encounter order. The returned Collector disallows null values and will throwNullPointerExceptionif it is presented with a null value.- Type Parameters:
- T- the type of the input elements
- Returns:
- a Collectorthat accumulates the input elements into an unmodifiable List in encounter order
- Since:
- 10
 
 - 
toSetpublic static <T> Collector<T,?,Set<T>> toSet() Returns aCollectorthat accumulates the input elements into a newSet. There are no guarantees on the type, mutability, serializability, or thread-safety of theSetreturned; if more control over the returnedSetis required, usetoCollection(Supplier).This is an unorderedCollector.- Type Parameters:
- T- the type of the input elements
- Returns:
- a Collectorwhich collects all the input elements into aSet
 
 - 
toUnmodifiableSetpublic static <T> Collector<T,?,Set<T>> toUnmodifiableSet() Returns aCollectorthat accumulates the input elements into an unmodifiable Set. The returned Collector disallows null values and will throwNullPointerExceptionif it is presented with a null value. If the input contains duplicate elements, an arbitrary element of the duplicates is preserved.This is an unorderedCollector.- Type Parameters:
- T- the type of the input elements
- Returns:
- a Collectorthat accumulates the input elements into an unmodifiable Set
- Since:
- 10
 
 - 
joiningpublic static Collector<CharSequence,?,String> joining() Returns aCollectorthat concatenates the input elements into aString, in encounter order.- Returns:
- a Collectorthat concatenates the input elements into aString, in encounter order
 
 - 
joiningpublic static Collector<CharSequence,?,String> joining(CharSequence delimiter) Returns aCollectorthat concatenates the input elements, separated by the specified delimiter, in encounter order.- Parameters:
- delimiter- the delimiter to be used between each element
- Returns:
- A Collectorwhich concatenates CharSequence elements, separated by the specified delimiter, in encounter order
 
 - 
joiningpublic static Collector<CharSequence,?,String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix) Returns aCollectorthat concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.- Parameters:
- 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
- Returns:
- A Collectorwhich concatenates CharSequence elements, separated by the specified delimiter, in encounter order
 
 - 
mappingpublic static <T,U,A,R> Collector<T,?,R> mapping(Function<? super T,? extends U> mapper, Collector<? super U,A,R> downstream) Adapts aCollectoraccepting elements of typeUto one accepting elements of typeTby applying a mapping function to each input element before accumulation.- API Note:
- The mapping()collectors are most useful when used in a multi-level reduction, such as downstream of agroupingByorpartitioningBy. For example, given a stream ofPerson, to accumulate the set of last names in each city:Map<City, Set<String>> lastNamesByCity = people.stream().collect( groupingBy(Person::getCity, mapping(Person::getLastName, toSet())));
- Type Parameters:
- 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
- Parameters:
- mapper- a function to be applied to the input elements
- downstream- a collector which will accept mapped values
- Returns:
- a collector which applies the mapping function to the input elements and provides the mapped results to the downstream collector
 
 - 
flatMappingpublic static <T,U,A,R> Collector<T,?,R> flatMapping(Function<? super T,? extends Stream<? extends U>> mapper, Collector<? super U,A,R> downstream) Adapts aCollectoraccepting elements of typeUto one accepting elements of typeTby applying a flat mapping function to each input element before accumulation. The flat mapping function maps an input element to astreamcovering zero or more output elements that are then accumulated downstream. Each mapped stream isclosedafter its contents have been placed downstream. (If a mapped stream isnullan empty stream is used, instead.)- API Note:
- The flatMapping()collectors are most useful when used in a multi-level reduction, such as downstream of agroupingByorpartitioningBy. For example, given a stream ofOrder, to accumulate the set of line items for each customer:Map<String, Set<LineItem>> itemsByCustomerName = orders.stream().collect( groupingBy(Order::getCustomerName, flatMapping(order -> order.getLineItems().stream(), toSet())));
- Type Parameters:
- 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
- Parameters:
- mapper- a function to be applied to the input elements, which returns a stream of results
- downstream- a collector which will receive the elements of the stream returned by mapper
- Returns:
- a collector which applies the mapping function to the input elements and provides the flat mapped results to the downstream collector
- Since:
- 9
 
 - 
filteringpublic static <T,A,R> Collector<T,?,R> filtering(Predicate<? super T> predicate, Collector<? super T,A,R> downstream) Adapts aCollectorto one accepting elements of the same typeTby applying the predicate to each input element and only accumulating if the predicate returnstrue.- API Note:
- The filtering()collectors are most useful when used in a multi-level reduction, such as downstream of agroupingByorpartitioningBy. For example, given a stream ofEmployee, to accumulate the employees in each department that have a salary above a certain threshold:
 A filtering collector differs from a stream'sMap<Department, Set<Employee>> wellPaidEmployeesByDepartment = employees.stream().collect( groupingBy(Employee::getDepartment, filtering(e -> e.getSalary() > 2000, toSet())));filter()operation. In this example, suppose there are no employees whose salary is above the threshold in some department. Using a filtering collector as shown above would result in a mapping from that department to an emptySet. If a streamfilter()operation were done instead, there would be no mapping for that department at all.
- Type Parameters:
- T- the type of the input elements
- A- intermediate accumulation type of the downstream collector
- R- result type of collector
- Parameters:
- predicate- a predicate to be applied to the input elements
- downstream- a collector which will accept values that match the predicate
- Returns:
- a collector which applies the predicate to the input elements and provides matching elements to the downstream collector
- Since:
- 9
 
 - 
collectingAndThenpublic static <T,A,R,RR> Collector<T,A,RR> collectingAndThen(Collector<T,A,R> downstream, Function<R,RR> finisher) Adapts aCollectorto perform an additional finishing transformation. For example, one could adapt thetoList()collector to always produce an immutable list with:List<String> list = people.stream().collect( collectingAndThen(toList(), Collections::unmodifiableList));- Type Parameters:
- 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
- Parameters:
- downstream- a collector
- finisher- a function to be applied to the final result of the downstream collector
- Returns:
- a collector which performs the action of the downstream collector, followed by an additional finishing step
 
 - 
countingpublic static <T> Collector<T,?,Long> counting() Returns aCollectoraccepting elements of typeTthat counts the number of input elements. If no elements are present, the result is 0.- Implementation Requirements:
- This produces a result equivalent to:
 reducing(0L, e -> 1L, Long::sum)
- Type Parameters:
- T- the type of the input elements
- Returns:
- a Collectorthat counts the input elements
 
 - 
minBypublic static <T> Collector<T,?,Optional<T>> minBy(Comparator<? super T> comparator) Returns aCollectorthat produces the minimal element according to a givenComparator, described as anOptional<T>.- Implementation Requirements:
- This produces a result equivalent to:
 reducing(BinaryOperator.minBy(comparator))
- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparator- a- Comparatorfor comparing elements
- Returns:
- a Collectorthat produces the minimal value
 
 - 
maxBypublic static <T> Collector<T,?,Optional<T>> maxBy(Comparator<? super T> comparator) Returns aCollectorthat produces the maximal element according to a givenComparator, described as anOptional<T>.- Implementation Requirements:
- This produces a result equivalent to:
 reducing(BinaryOperator.maxBy(comparator))
- Type Parameters:
- T- the type of the input elements
- Parameters:
- comparator- a- Comparatorfor comparing elements
- Returns:
- a Collectorthat produces the maximal value
 
 - 
summingIntpublic static <T> Collector<T,?,Integer> summingInt(ToIntFunction<? super T> mapper) Returns aCollectorthat produces the sum of a integer-valued function applied to the input elements. If no elements are present, the result is 0.- Type Parameters:
- T- the type of the input elements
- Parameters:
- mapper- a function extracting the property to be summed
- Returns:
- a Collectorthat produces the sum of a derived property
 
 - 
summingLongpublic static <T> Collector<T,?,Long> summingLong(ToLongFunction<? super T> mapper) Returns aCollectorthat produces the sum of a long-valued function applied to the input elements. If no elements are present, the result is 0.- Type Parameters:
- T- the type of the input elements
- Parameters:
- mapper- a function extracting the property to be summed
- Returns:
- a Collectorthat produces the sum of a derived property
 
 - 
summingDoublepublic static <T> Collector<T,?,Double> summingDouble(ToDoubleFunction<? super T> mapper) Returns aCollectorthat 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 NaNor the sum is at any point aNaNthen the sum will beNaN.- Type Parameters:
- T- the type of the input elements
- Parameters:
- mapper- a function extracting the property to be summed
- Returns:
- a Collectorthat produces the sum of a derived property
 
 - 
averagingIntpublic static <T> Collector<T,?,Double> averagingInt(ToIntFunction<? super T> mapper) Returns aCollectorthat produces the arithmetic mean of an integer-valued function applied to the input elements. If no elements are present, the result is 0.- Type Parameters:
- T- the type of the input elements
- Parameters:
- mapper- a function extracting the property to be averaged
- Returns:
- a Collectorthat produces the arithmetic mean of a derived property
 
 - 
averagingLongpublic static <T> Collector<T,?,Double> averagingLong(ToLongFunction<? super T> mapper) Returns aCollectorthat produces the arithmetic mean of a long-valued function applied to the input elements. If no elements are present, the result is 0.- Type Parameters:
- T- the type of the input elements
- Parameters:
- mapper- a function extracting the property to be averaged
- Returns:
- a Collectorthat produces the arithmetic mean of a derived property
 
 - 
averagingDoublepublic static <T> Collector<T,?,Double> averagingDouble(ToDoubleFunction<? super T> mapper) Returns aCollectorthat 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 NaNor the sum is at any point aNaNthen the average will beNaN.- Implementation Note:
- The doubleformat can represent all consecutive integers in the range -253 to 253. If the pipeline has more than 253 values, the divisor in the average computation will saturate at 253, leading to additional numerical errors.
- Type Parameters:
- T- the type of the input elements
- Parameters:
- mapper- a function extracting the property to be averaged
- Returns:
- a Collectorthat produces the arithmetic mean of a derived property
 
 - 
reducingpublic static <T> Collector<T,?,T> reducing(T identity, BinaryOperator<T> op) Returns aCollectorwhich performs a reduction of its input elements under a specifiedBinaryOperatorusing the provided identity.- API Note:
- The reducing()collectors are most useful when used in a multi-level reduction, downstream ofgroupingByorpartitioningBy. To perform a simple reduction on a stream, useStream.reduce(Object, BinaryOperator)} instead.
- Type Parameters:
- T- element type for the input and output of the reduction
- Parameters:
- 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
- Returns:
- a Collectorwhich implements the reduction operation
- See Also:
- reducing(BinaryOperator),- reducing(Object, Function, BinaryOperator)
 
 - 
reducingpublic static <T> Collector<T,?,Optional<T>> reducing(BinaryOperator<T> op) Returns aCollectorwhich performs a reduction of its input elements under a specifiedBinaryOperator. The result is described as anOptional<T>.- API Note:
- The reducing()collectors are most useful when used in a multi-level reduction, downstream ofgroupingByorpartitioningBy. To perform a simple reduction on a stream, useStream.reduce(BinaryOperator)instead.For example, given a stream of Person, to calculate tallest person in each city:Comparator<Person> byHeight = Comparator.comparing(Person::getHeight); Map<City, Optional<Person>> tallestByCity = people.stream().collect( groupingBy(Person::getCity, reducing(BinaryOperator.maxBy(byHeight))));
- Type Parameters:
- T- element type for the input and output of the reduction
- Parameters:
- op- a- BinaryOperator<T>used to reduce the input elements
- Returns:
- a Collectorwhich implements the reduction operation
- See Also:
- reducing(Object, BinaryOperator),- reducing(Object, Function, BinaryOperator)
 
 - 
reducingpublic static <T,U> Collector<T,?,U> reducing(U identity, Function<? super T,? extends U> mapper, BinaryOperator<U> op) Returns aCollectorwhich performs a reduction of its input elements under a specified mapping function andBinaryOperator. This is a generalization ofreducing(Object, BinaryOperator)which allows a transformation of the elements before reduction.- API Note:
- The reducing()collectors are most useful when used in a multi-level reduction, downstream ofgroupingByorpartitioningBy. To perform a simple map-reduce on a stream, useStream.map(Function)andStream.reduce(Object, BinaryOperator)instead.For example, given a stream of Person, to calculate the longest last name of residents in each city:Comparator<String> byLength = Comparator.comparing(String::length); Map<City, String> longestLastNameByCity = people.stream().collect( groupingBy(Person::getCity, reducing("", Person::getLastName, BinaryOperator.maxBy(byLength))));
- Type Parameters:
- T- the type of the input elements
- U- the type of the mapped values
- Parameters:
- 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
- Returns:
- a Collectorimplementing the map-reduce operation
- See Also:
- reducing(Object, BinaryOperator),- reducing(BinaryOperator)
 
 - 
groupingBypublic static <T,K> Collector<T,?,Map<K,List<T>>> groupingBy(Function<? super T,? extends K> classifier) Returns aCollectorimplementing a "group by" operation on input elements of typeT, grouping elements according to a classification function, and returning the results in aMap.The classification function maps elements to some key type K. The collector produces aMap<K, List<T>>whose keys are the values resulting from applying the classification function to the input elements, and whose corresponding values areLists 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 MaporListobjects returned.- Implementation Requirements:
- This produces a result similar to:
 groupingBy(classifier, toList());
- Implementation Note:
- The returned Collectoris not concurrent. For parallel stream pipelines, thecombinerfunction operates by merging the keys from one map into another, which can be an expensive operation. If preservation of the order in which elements appear in the resultingMapcollector is not required, usinggroupingByConcurrent(Function)may offer better parallel performance.
- Type Parameters:
- T- the type of the input elements
- K- the type of the keys
- Parameters:
- classifier- the classifier function mapping input elements to keys
- Returns:
- a Collectorimplementing the group-by operation
- See Also:
- groupingBy(Function, Collector),- groupingBy(Function, Supplier, Collector),- groupingByConcurrent(Function)
 
 - 
groupingBypublic static <T,K,A,D> Collector<T,?,Map<K,D>> groupingBy(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream) Returns aCollectorimplementing 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.The classification function maps elements to some key type K. The downstream collector operates on elements of typeTand produces a result of typeD. The resulting collector produces aMap<K, D>.There are no guarantees on the type, mutability, serializability, or thread-safety of the Mapreturned.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())));- Implementation Note:
- The returned Collectoris not concurrent. For parallel stream pipelines, thecombinerfunction operates by merging the keys from one map into another, which can be an expensive operation. If preservation of the order in which elements are presented to the downstream collector is not required, usinggroupingByConcurrent(Function, Collector)may offer better parallel performance.
- Type Parameters:
- 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
- Parameters:
- classifier- a classifier function mapping input elements to keys
- downstream- a- Collectorimplementing the downstream reduction
- Returns:
- a Collectorimplementing the cascaded group-by operation
- See Also:
- groupingBy(Function),- groupingBy(Function, Supplier, Collector),- groupingByConcurrent(Function, Collector)
 
 - 
groupingBypublic 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) Returns aCollectorimplementing 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. TheMapproduced 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 typeTand produces a result of typeD. The resulting collector produces aMap<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())));- Implementation Note:
- The returned Collectoris not concurrent. For parallel stream pipelines, thecombinerfunction operates by merging the keys from one map into another, which can be an expensive operation. If preservation of the order in which elements are presented to the downstream collector is not required, usinggroupingByConcurrent(Function, Supplier, Collector)may offer better parallel performance.
- Type Parameters:
- 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
- Parameters:
- classifier- a classifier function mapping input elements to keys
- downstream- a- Collectorimplementing the downstream reduction
- mapFactory- a supplier providing a new empty- Mapinto which the results will be inserted
- Returns:
- a Collectorimplementing the cascaded group-by operation
- See Also:
- groupingBy(Function, Collector),- groupingBy(Function),- groupingByConcurrent(Function, Supplier, Collector)
 
 - 
groupingByConcurrentpublic static <T,K> Collector<T,?,ConcurrentMap<K,List<T>>> groupingByConcurrent(Function<? super T,? extends K> classifier) Returns a concurrentCollectorimplementing a "group by" operation on input elements of typeT, grouping elements according to a classification function.This is a concurrentandunorderedCollector.The classification function maps elements to some key type K. The collector produces aConcurrentMap<K, List<T>>whose keys are the values resulting from applying the classification function to the input elements, and whose corresponding values areLists 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 ConcurrentMaporListobjects returned, or of the thread-safety of theListobjects returned.- Implementation Requirements:
- This produces a result similar to:
 groupingByConcurrent(classifier, toList());
- Type Parameters:
- T- the type of the input elements
- K- the type of the keys
- Parameters:
- classifier- a classifier function mapping input elements to keys
- Returns:
- a concurrent, unordered Collectorimplementing the group-by operation
- See Also:
- groupingBy(Function),- groupingByConcurrent(Function, Collector),- groupingByConcurrent(Function, Supplier, Collector)
 
 - 
groupingByConcurrentpublic static <T,K,A,D> Collector<T,?,ConcurrentMap<K,D>> groupingByConcurrent(Function<? super T,? extends K> classifier, Collector<? super T,A,D> downstream) Returns a concurrentCollectorimplementing 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.This is a concurrentandunorderedCollector.The classification function maps elements to some key type K. The downstream collector operates on elements of typeTand produces a result of typeD. The resulting collector produces aConcurrentMap<K, D>.There are no guarantees on the type, mutability, or serializability of the ConcurrentMapreturned.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())));- Type Parameters:
- 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
- Parameters:
- classifier- a classifier function mapping input elements to keys
- downstream- a- Collectorimplementing the downstream reduction
- Returns:
- a concurrent, unordered Collectorimplementing the cascaded group-by operation
- See Also:
- groupingBy(Function, Collector),- groupingByConcurrent(Function),- groupingByConcurrent(Function, Supplier, Collector)
 
 - 
groupingByConcurrentpublic 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) Returns a concurrentCollectorimplementing 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. TheConcurrentMapproduced by the Collector is created with the supplied factory function.This is a concurrentandunorderedCollector.The classification function maps elements to some key type K. The downstream collector operates on elements of typeTand produces a result of typeD. The resulting collector produces aConcurrentMap<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, ConcurrentSkipListMap::new, mapping(Person::getLastName, toSet())));- Type Parameters:
- 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
- Parameters:
- classifier- a classifier function mapping input elements to keys
- downstream- a- Collectorimplementing the downstream reduction
- mapFactory- a supplier providing a new empty- ConcurrentMapinto which the results will be inserted
- Returns:
- a concurrent, unordered Collectorimplementing the cascaded group-by operation
- See Also:
- groupingByConcurrent(Function),- groupingByConcurrent(Function, Collector),- groupingBy(Function, Supplier, Collector)
 
 - 
partitioningBypublic static <T> Collector<T,?,Map<Boolean,List<T>>> partitioningBy(Predicate<? super T> predicate) Returns aCollectorwhich partitions the input elements according to aPredicate, and organizes them into aMap<Boolean, List<T>>. The returnedMapalways contains mappings for bothfalseandtruekeys. There are no guarantees on the type, mutability, serializability, or thread-safety of theMaporListreturned.- API Note:
- If a partition has no elements, its value in the result Map will be an empty List.
- Type Parameters:
- T- the type of the input elements
- Parameters:
- predicate- a predicate used for classifying input elements
- Returns:
- a Collectorimplementing the partitioning operation
- See Also:
- partitioningBy(Predicate, Collector)
 
 - 
partitioningBypublic static <T,D,A> Collector<T,?,Map<Boolean,D>> partitioningBy(Predicate<? super T> predicate, Collector<? super T,A,D> downstream) Returns aCollectorwhich 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.The returned Mapalways contains mappings for bothfalseandtruekeys. There are no guarantees on the type, mutability, serializability, or thread-safety of theMapreturned.- API Note:
- If a partition has no elements, its value in the result Map will be obtained by calling the downstream collector's supplier function and then applying the finisher function.
- Type Parameters:
- T- the type of the input elements
- A- the intermediate accumulation type of the downstream collector
- D- the result type of the downstream reduction
- Parameters:
- predicate- a predicate used for classifying input elements
- downstream- a- Collectorimplementing the downstream reduction
- Returns:
- a Collectorimplementing the cascaded partitioning operation
- See Also:
- partitioningBy(Predicate)
 
 - 
toMappublic static <T,K,U> Collector<T,?,Map<K,U>> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper) Returns aCollectorthat accumulates elements into aMapwhose keys and values are the result of applying the provided mapping functions to the input elements.If the mapped keys contain duplicates (according to Object.equals(Object)), anIllegalStateExceptionis thrown when the collection operation is performed. If the mapped keys might have duplicates, usetoMap(Function, Function, BinaryOperator)instead.There are no guarantees on the type, mutability, serializability, or thread-safety of the Mapreturned.- API Note:
- It is common for either the key or the value to be the input elements.
 In this case, the utility method
 Function.identity()may be helpful. For example, the following produces aMapmapping students to their grade point average:
 And the following produces aMap<Student, Double> studentToGPA = students.stream().collect( toMap(Function.identity(), student -> computeGPA(student)));Mapmapping a unique identifier to students:Map<String, Student> studentIdToStudent = students.stream().collect( toMap(Student::getId, Function.identity()));
- Implementation Note:
- The returned Collectoris not concurrent. For parallel stream pipelines, thecombinerfunction operates by merging the keys from one map into another, which can be an expensive operation. If it is not required that results are inserted into theMapin encounter order, usingtoConcurrentMap(Function, Function)may offer better parallel performance.
- Type Parameters:
- 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
- Parameters:
- keyMapper- a mapping function to produce keys
- valueMapper- a mapping function to produce values
- Returns:
- a Collectorwhich collects elements into aMapwhose keys and values are the result of applying mapping functions to the input elements
- See Also:
- toMap(Function, Function, BinaryOperator),- toMap(Function, Function, BinaryOperator, Supplier),- toConcurrentMap(Function, Function)
 
 - 
toUnmodifiableMappublic static <T,K,U> Collector<T,?,Map<K,U>> toUnmodifiableMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper) Returns aCollectorthat 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.If the mapped keys contain duplicates (according to Object.equals(Object)), anIllegalStateExceptionis thrown when the collection operation is performed. If the mapped keys might have duplicates, usetoUnmodifiableMap(Function, Function, BinaryOperator)to handle merging of the values.The returned Collector disallows null keys and values. If either mapping function returns null, NullPointerExceptionwill be thrown.- Type Parameters:
- 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
- Parameters:
- keyMapper- a mapping function to produce keys, must be non-null
- valueMapper- a mapping function to produce values, must be non-null
- Returns:
- a Collectorthat 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
- Throws:
- NullPointerException- if either keyMapper or valueMapper is null
- Since:
- 10
- See Also:
- toUnmodifiableMap(Function, Function, BinaryOperator)
 
 - 
toMappublic 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) Returns aCollectorthat accumulates elements into aMapwhose keys and values are the result of applying the provided mapping functions to the input elements.If the mapped keys contain duplicates (according to Object.equals(Object)), the value mapping function is applied to each equal element, and the results are merged using the provided merging function.There are no guarantees on the type, mutability, serializability, or thread-safety of the Mapreturned.- API Note:
- There are multiple ways to deal with collisions between multiple elements
 mapping to the same key.  The other forms of toMapsimply use a merge function that throws unconditionally, but you can easily write more flexible merge policies. For example, if you have a stream ofPerson, and you want to produce a "phone book" mapping name to address, but it is possible that two persons have the same name, you can do as follows to gracefully deal with these collisions, and produce aMapmapping names to a concatenated list of addresses:Map<String, String> phoneBook = people.stream().collect( toMap(Person::getName, Person::getAddress, (s, a) -> s + ", " + a));
- Implementation Note:
- The returned Collectoris not concurrent. For parallel stream pipelines, thecombinerfunction operates by merging the keys from one map into another, which can be an expensive operation. If it is not required that results are merged into theMapin encounter order, usingtoConcurrentMap(Function, Function, BinaryOperator)may offer better parallel performance.
- Type Parameters:
- 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
- Parameters:
- 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)
- Returns:
- a Collectorwhich collects elements into aMapwhose 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
- See Also:
- toMap(Function, Function),- toMap(Function, Function, BinaryOperator, Supplier),- toConcurrentMap(Function, Function, BinaryOperator)
 
 - 
toUnmodifiableMappublic static <T,K,U> Collector<T,?,Map<K,U>> toUnmodifiableMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction) Returns aCollectorthat 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.If the mapped keys contain duplicates (according to Object.equals(Object)), the value mapping function is applied to each equal element, and the results are merged using the provided merging function.The returned Collector disallows null keys and values. If either mapping function returns null, NullPointerExceptionwill be thrown.- Type Parameters:
- 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
- Parameters:
- keyMapper- a mapping function to produce keys, must be non-null
- valueMapper- a mapping function to produce values, must be non-null
- mergeFunction- a merge function, used to resolve collisions between values associated with the same key, as supplied to- Map.merge(Object, Object, BiFunction), must be non-null
- Returns:
- a Collectorthat 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
- Throws:
- NullPointerException- if the keyMapper, valueMapper, or mergeFunction is null
- Since:
- 10
- See Also:
- toUnmodifiableMap(Function, Function)
 
 - 
toMappublic 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> mapFactory) Returns aCollectorthat accumulates elements into aMapwhose keys and values are the result of applying the provided mapping functions to the input elements.If the mapped keys contain duplicates (according to Object.equals(Object)), the value mapping function is applied to each equal element, and the results are merged using the provided merging function. TheMapis created by a provided supplier function.- Implementation Note:
- The returned Collectoris not concurrent. For parallel stream pipelines, thecombinerfunction operates by merging the keys from one map into another, which can be an expensive operation. If it is not required that results are merged into theMapin encounter order, usingtoConcurrentMap(Function, Function, BinaryOperator, Supplier)may offer better parallel performance.
- Type Parameters:
- 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
- Parameters:
- 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)
- mapFactory- a supplier providing a new empty- Mapinto which the results will be inserted
- Returns:
- a Collectorwhich collects elements into aMapwhose 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
- See Also:
- toMap(Function, Function),- toMap(Function, Function, BinaryOperator),- toConcurrentMap(Function, Function, BinaryOperator, Supplier)
 
 - 
toConcurrentMappublic static <T,K,U> Collector<T,?,ConcurrentMap<K,U>> toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper) Returns a concurrentCollectorthat accumulates elements into aConcurrentMapwhose keys and values are the result of applying the provided mapping functions to the input elements.If the mapped keys contain duplicates (according to Object.equals(Object)), anIllegalStateExceptionis thrown when the collection operation is performed. If the mapped keys may have duplicates, usetoConcurrentMap(Function, Function, BinaryOperator)instead.There are no guarantees on the type, mutability, or serializability of the ConcurrentMapreturned.- API Note:
- It is common for either the key or the value to be the input elements.
 In this case, the utility method
 Function.identity()may be helpful. For example, the following produces aConcurrentMapmapping students to their grade point average:
 And the following produces aConcurrentMap<Student, Double> studentToGPA = students.stream().collect( toConcurrentMap(Function.identity(), student -> computeGPA(student)));ConcurrentMapmapping a unique identifier to students:ConcurrentMap<String, Student> studentIdToStudent = students.stream().collect( toConcurrentMap(Student::getId, Function.identity()));This is a concurrentandunorderedCollector.
- Type Parameters:
- 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
- Parameters:
- keyMapper- the mapping function to produce keys
- valueMapper- the mapping function to produce values
- Returns:
- a concurrent, unordered Collectorwhich collects elements into aConcurrentMapwhose 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
- See Also:
- toMap(Function, Function),- toConcurrentMap(Function, Function, BinaryOperator),- toConcurrentMap(Function, Function, BinaryOperator, Supplier)
 
 - 
toConcurrentMappublic 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) Returns a concurrentCollectorthat accumulates elements into aConcurrentMapwhose keys and values are the result of applying the provided mapping functions to the input elements.If the mapped keys contain duplicates (according to Object.equals(Object)), the value mapping function is applied to each equal element, and the results are merged using the provided merging function.There are no guarantees on the type, mutability, or serializability of the ConcurrentMapreturned.- API Note:
- There are multiple ways to deal with collisions between multiple elements
 mapping to the same key.  The other forms of toConcurrentMapsimply use a merge function that throws unconditionally, but you can easily write more flexible merge policies. For example, if you have a stream ofPerson, and you want to produce a "phone book" mapping name to address, but it is possible that two persons have the same name, you can do as follows to gracefully deal with these collisions, and produce aConcurrentMapmapping names to a concatenated list of addresses:ConcurrentMap<String, String> phoneBook = people.stream().collect( toConcurrentMap(Person::getName, Person::getAddress, (s, a) -> s + ", " + a));This is a concurrentandunorderedCollector.
- Type Parameters:
- 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
- Parameters:
- 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)
- Returns:
- a concurrent, unordered Collectorwhich collects elements into aConcurrentMapwhose 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
- See Also:
- toConcurrentMap(Function, Function),- toConcurrentMap(Function, Function, BinaryOperator, Supplier),- toMap(Function, Function, BinaryOperator)
 
 - 
toConcurrentMappublic 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> mapFactory) Returns a concurrentCollectorthat accumulates elements into aConcurrentMapwhose keys and values are the result of applying the provided mapping functions to the input elements.If the mapped keys contain duplicates (according to Object.equals(Object)), the value mapping function is applied to each equal element, and the results are merged using the provided merging function. TheConcurrentMapis created by a provided supplier function.This is a concurrentandunorderedCollector.- Type Parameters:
- 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
- Parameters:
- 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)
- mapFactory- a supplier providing a new empty- ConcurrentMapinto which the results will be inserted
- Returns:
- a concurrent, unordered Collectorwhich collects elements into aConcurrentMapwhose 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
- See Also:
- toConcurrentMap(Function, Function),- toConcurrentMap(Function, Function, BinaryOperator),- toMap(Function, Function, BinaryOperator, Supplier)
 
 - 
summarizingIntpublic static <T> Collector<T,?,IntSummaryStatistics> summarizingInt(ToIntFunction<? super T> mapper) Returns aCollectorwhich applies anint-producing mapping function to each input element, and returns summary statistics for the resulting values.- Type Parameters:
- T- the type of the input elements
- Parameters:
- mapper- a mapping function to apply to each element
- Returns:
- a Collectorimplementing the summary-statistics reduction
- See Also:
- summarizingDouble(ToDoubleFunction),- summarizingLong(ToLongFunction)
 
 - 
summarizingLongpublic static <T> Collector<T,?,LongSummaryStatistics> summarizingLong(ToLongFunction<? super T> mapper) Returns aCollectorwhich applies anlong-producing mapping function to each input element, and returns summary statistics for the resulting values.- Type Parameters:
- T- the type of the input elements
- Parameters:
- mapper- the mapping function to apply to each element
- Returns:
- a Collectorimplementing the summary-statistics reduction
- See Also:
- summarizingDouble(ToDoubleFunction),- summarizingInt(ToIntFunction)
 
 - 
summarizingDoublepublic static <T> Collector<T,?,DoubleSummaryStatistics> summarizingDouble(ToDoubleFunction<? super T> mapper) Returns aCollectorwhich applies andouble-producing mapping function to each input element, and returns summary statistics for the resulting values.- Type Parameters:
- T- the type of the input elements
- Parameters:
- mapper- a mapping function to apply to each element
- Returns:
- a Collectorimplementing the summary-statistics reduction
- See Also:
- summarizingLong(ToLongFunction),- summarizingInt(ToIntFunction)
 
 
- 
 
-