Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/java/util/stream/Collectors#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/util/stream/Collectors#inhmethods)

# Collectors

` public final class Collectors `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.util.stream.Collectors |

<br />

*** ** * ** ***

Implementations of `https://developer.android.com/reference/java/util/stream/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));

<br />

## Summary

| ### Public methods ||
|---|---|
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Double>` | ` https://developer.android.com/reference/java/util/stream/Collectors#averagingDouble(java.util.function.ToDoubleFunction<?%20super%20T>)(https://developer.android.com/reference/java/util/function/ToDoubleFunction<? super T> mapper) ` Returns a `Collector` that produces the arithmetic mean of a double-valued function applied to the input elements. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Double>` | ` https://developer.android.com/reference/java/util/stream/Collectors#averagingInt(java.util.function.ToIntFunction<?%20super%20T>)(https://developer.android.com/reference/java/util/function/ToIntFunction<? super T> mapper) ` Returns a `Collector` that produces the arithmetic mean of an integer-valued function applied to the input elements. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Double>` | ` https://developer.android.com/reference/java/util/stream/Collectors#averagingLong(java.util.function.ToLongFunction<?%20super%20T>)(https://developer.android.com/reference/java/util/function/ToLongFunction<? super T> mapper) ` Returns a `Collector` that produces the arithmetic mean of a long-valued function applied to the input elements. |
| ` static <T, A, R, RR> https://developer.android.com/reference/java/util/stream/Collector<T, A, RR>` | ` https://developer.android.com/reference/java/util/stream/Collectors#collectingAndThen(java.util.stream.Collector<T,A,R>,%20java.util.function.Function<R,RR>)(https://developer.android.com/reference/java/util/stream/Collector<T, A, R> downstream, https://developer.android.com/reference/java/util/function/Function<R, RR> finisher) ` Adapts a `Collector` to perform an additional finishing transformation. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Long>` | ` https://developer.android.com/reference/java/util/stream/Collectors#counting()() ` Returns a `Collector` accepting elements of type `T` that counts the number of input elements. |
| ` static <T, A, R> https://developer.android.com/reference/java/util/stream/Collector<T, ?, R>` | ` https://developer.android.com/reference/java/util/stream/Collectors#filtering(java.util.function.Predicate<?%20super%20T>,%20java.util.stream.Collector<?%20super%20T,A,R>)(https://developer.android.com/reference/java/util/function/Predicate<? super T> predicate, https://developer.android.com/reference/java/util/stream/Collector<? super T, A, R> downstream) ` Adapts a `Collector` to one accepting elements of the same type `T` by applying the predicate to each input element and only accumulating if the predicate returns `true`. |
| ` static <T, U, A, R> https://developer.android.com/reference/java/util/stream/Collector<T, ?, R>` | ` https://developer.android.com/reference/java/util/stream/Collectors#flatMapping(java.util.function.Function<?%20super%20T,?%20extends%20java.util.stream.Stream<?%20extends%20U>>,%20java.util.stream.Collector<?%20super%20U,A,R>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends https://developer.android.com/reference/java/util/stream/Stream<? extends U>> mapper, https://developer.android.com/reference/java/util/stream/Collector<? super U, A, R> downstream) ` Adapts a `Collector` accepting elements of type `U` to one accepting elements of type `T` by applying a flat mapping function to each input element before accumulation. |
| ` static <T, K, D, A, M extends https://developer.android.com/reference/java/util/Map<K, D>> https://developer.android.com/reference/java/util/stream/Collector<T, ?, M>` | ` https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Supplier<M>,%20java.util.stream.Collector<?%20super%20T,A,D>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> classifier, https://developer.android.com/reference/java/util/function/Supplier<M> mapFactory, https://developer.android.com/reference/java/util/stream/Collector<? super T, A, D> downstream) ` 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, K> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, https://developer.android.com/reference/java/util/List<T>>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> classifier) ` 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, K, A, D> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, D>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.stream.Collector<?%20super%20T,A,D>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> classifier, https://developer.android.com/reference/java/util/stream/Collector<? super T, A, D> downstream) ` 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, K, A, D, M extends https://developer.android.com/reference/java/util/concurrent/ConcurrentMap<K, D>> https://developer.android.com/reference/java/util/stream/Collector<T, ?, M>` | ` https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Supplier<M>,%20java.util.stream.Collector<?%20super%20T,A,D>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> classifier, https://developer.android.com/reference/java/util/function/Supplier<M> mapFactory, https://developer.android.com/reference/java/util/stream/Collector<? super T, A, D> downstream) ` 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, K, A, D> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/concurrent/ConcurrentMap<K, D>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.stream.Collector<?%20super%20T,A,D>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> classifier, https://developer.android.com/reference/java/util/stream/Collector<? super T, A, D> downstream) ` 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, K> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/concurrent/ConcurrentMap<K, https://developer.android.com/reference/java/util/List<T>>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> classifier) ` Returns a concurrent `Collector` implementing a "group by" operation on input elements of type `T`, grouping elements according to a classification function. |
| ` static https://developer.android.com/reference/java/util/stream/Collector<https://developer.android.com/reference/java/lang/CharSequence, ?, https://developer.android.com/reference/java/lang/String>` | ` https://developer.android.com/reference/java/util/stream/Collectors#joining(java.lang.CharSequence,%20java.lang.CharSequence,%20java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence delimiter, https://developer.android.com/reference/java/lang/CharSequence prefix, https://developer.android.com/reference/java/lang/CharSequence suffix) ` Returns a `Collector` that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order. |
| ` static https://developer.android.com/reference/java/util/stream/Collector<https://developer.android.com/reference/java/lang/CharSequence, ?, https://developer.android.com/reference/java/lang/String>` | ` https://developer.android.com/reference/java/util/stream/Collectors#joining(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence delimiter) ` Returns a `Collector` that concatenates the input elements, separated by the specified delimiter, in encounter order. |
| ` static https://developer.android.com/reference/java/util/stream/Collector<https://developer.android.com/reference/java/lang/CharSequence, ?, https://developer.android.com/reference/java/lang/String>` | ` https://developer.android.com/reference/java/util/stream/Collectors#joining()() ` Returns a `Collector` that concatenates the input elements into a `String`, in encounter order. |
| ` static <T, U, A, R> https://developer.android.com/reference/java/util/stream/Collector<T, ?, R>` | ` https://developer.android.com/reference/java/util/stream/Collectors#mapping(java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.stream.Collector<?%20super%20U,A,R>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends U> mapper, https://developer.android.com/reference/java/util/stream/Collector<? super U, A, R> downstream) ` 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> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Optional<T>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#maxBy(java.util.Comparator<?%20super%20T>)(https://developer.android.com/reference/java/util/Comparator<? super T> comparator) ` Returns a `Collector` that produces the maximal element according to a given `Comparator`, described as an `Optional<T>`. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Optional<T>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#minBy(java.util.Comparator<?%20super%20T>)(https://developer.android.com/reference/java/util/Comparator<? super T> comparator) ` Returns a `Collector` that produces the minimal element according to a given `Comparator`, described as an `Optional<T>`. |
| ` static <T, D, A> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/Boolean, D>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#partitioningBy(java.util.function.Predicate<?%20super%20T>,%20java.util.stream.Collector<?%20super%20T,A,D>)(https://developer.android.com/reference/java/util/function/Predicate<? super T> predicate, https://developer.android.com/reference/java/util/stream/Collector<? super T, A, D> downstream) ` 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> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/Boolean, https://developer.android.com/reference/java/util/List<T>>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#partitioningBy(java.util.function.Predicate<?%20super%20T>)(https://developer.android.com/reference/java/util/function/Predicate<? super T> predicate) ` Returns a `Collector` which partitions the input elements according to a `Predicate`, and organizes them into a `Map<Boolean, List<T>>`. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Optional<T>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#reducing(java.util.function.BinaryOperator<T>)(https://developer.android.com/reference/java/util/function/BinaryOperator<T> op) ` Returns a `Collector` which performs a reduction of its input elements under a specified `BinaryOperator`. |
| ` static <T, U> https://developer.android.com/reference/java/util/stream/Collector<T, ?, U>` | ` https://developer.android.com/reference/java/util/stream/Collectors#reducing(U,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)(U identity, https://developer.android.com/reference/java/util/function/Function<? super T, ? extends U> mapper, https://developer.android.com/reference/java/util/function/BinaryOperator<U> op) ` Returns a `Collector` which performs a reduction of its input elements under a specified mapping function and `BinaryOperator`. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, T>` | ` https://developer.android.com/reference/java/util/stream/Collectors#reducing(T,%20java.util.function.BinaryOperator<T>)(T identity, https://developer.android.com/reference/java/util/function/BinaryOperator<T> op) ` Returns a `Collector` which performs a reduction of its input elements under a specified `BinaryOperator` using the provided identity. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/DoubleSummaryStatistics>` | ` https://developer.android.com/reference/java/util/stream/Collectors#summarizingDouble(java.util.function.ToDoubleFunction<?%20super%20T>)(https://developer.android.com/reference/java/util/function/ToDoubleFunction<? super T> mapper) ` Returns a `Collector` which applies an `double`-producing mapping function to each input element, and returns summary statistics for the resulting values. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/IntSummaryStatistics>` | ` https://developer.android.com/reference/java/util/stream/Collectors#summarizingInt(java.util.function.ToIntFunction<?%20super%20T>)(https://developer.android.com/reference/java/util/function/ToIntFunction<? super T> mapper) ` Returns a `Collector` which applies an `int`-producing mapping function to each input element, and returns summary statistics for the resulting values. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/LongSummaryStatistics>` | ` https://developer.android.com/reference/java/util/stream/Collectors#summarizingLong(java.util.function.ToLongFunction<?%20super%20T>)(https://developer.android.com/reference/java/util/function/ToLongFunction<? super T> mapper) ` Returns a `Collector` which applies an `long`-producing mapping function to each input element, and returns summary statistics for the resulting values. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Double>` | ` https://developer.android.com/reference/java/util/stream/Collectors#summingDouble(java.util.function.ToDoubleFunction<?%20super%20T>)(https://developer.android.com/reference/java/util/function/ToDoubleFunction<? super T> mapper) ` Returns a `Collector` that produces the sum of a double-valued function applied to the input elements. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Integer>` | ` https://developer.android.com/reference/java/util/stream/Collectors#summingInt(java.util.function.ToIntFunction<?%20super%20T>)(https://developer.android.com/reference/java/util/function/ToIntFunction<? super T> mapper) ` Returns a `Collector` that produces the sum of an integer-valued function applied to the input elements. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Long>` | ` https://developer.android.com/reference/java/util/stream/Collectors#summingLong(java.util.function.ToLongFunction<?%20super%20T>)(https://developer.android.com/reference/java/util/function/ToLongFunction<? super T> mapper) ` Returns a `Collector` that produces the sum of a long-valued function applied to the input elements. |
| ` static <T, R1, R2, R> https://developer.android.com/reference/java/util/stream/Collector<T, ?, R>` | ` https://developer.android.com/reference/java/util/stream/Collectors#teeing(java.util.stream.Collector<?%20super%20T,?,R1>,%20java.util.stream.Collector<?%20super%20T,?,R2>,%20java.util.function.BiFunction<?%20super%20R1,?%20super%20R2,R>)(https://developer.android.com/reference/java/util/stream/Collector<? super T, ?, R1> downstream1, https://developer.android.com/reference/java/util/stream/Collector<? super T, ?, R2> downstream2, https://developer.android.com/reference/java/util/function/BiFunction<? super R1, ? super R2, R> merger) ` Returns a `Collector` that is a composite of two downstream collectors. |
| ` static <T, C extends https://developer.android.com/reference/java/util/Collection<T>> https://developer.android.com/reference/java/util/stream/Collector<T, ?, C>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toCollection(java.util.function.Supplier<C>)(https://developer.android.com/reference/java/util/function/Supplier<C> collectionFactory) ` Returns a `Collector` that accumulates the input elements into a new `Collection`, in encounter order. |
| ` static <T, K, U> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/concurrent/ConcurrentMap<K, U>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> keyMapper, https://developer.android.com/reference/java/util/function/Function<? super T, ? extends U> valueMapper) ` 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, K, U, M extends https://developer.android.com/reference/java/util/concurrent/ConcurrentMap<K, U>> https://developer.android.com/reference/java/util/stream/Collector<T, ?, M>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>,%20java.util.function.Supplier<M>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> keyMapper, https://developer.android.com/reference/java/util/function/Function<? super T, ? extends U> valueMapper, https://developer.android.com/reference/java/util/function/BinaryOperator<U> mergeFunction, https://developer.android.com/reference/java/util/function/Supplier<M> mapFactory) ` 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, K, U> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/concurrent/ConcurrentMap<K, U>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> keyMapper, https://developer.android.com/reference/java/util/function/Function<? super T, ? extends U> valueMapper, https://developer.android.com/reference/java/util/function/BinaryOperator<U> mergeFunction) ` 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> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/List<T>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toList()() ` Returns a `Collector` that accumulates the input elements into a new `List`. |
| ` static <T, K, U, M extends https://developer.android.com/reference/java/util/Map<K, U>> https://developer.android.com/reference/java/util/stream/Collector<T, ?, M>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>,%20java.util.function.Supplier<M>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> keyMapper, https://developer.android.com/reference/java/util/function/Function<? super T, ? extends U> valueMapper, https://developer.android.com/reference/java/util/function/BinaryOperator<U> mergeFunction, https://developer.android.com/reference/java/util/function/Supplier<M> mapFactory) ` 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, K, U> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, U>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> keyMapper, https://developer.android.com/reference/java/util/function/Function<? super T, ? extends U> valueMapper, https://developer.android.com/reference/java/util/function/BinaryOperator<U> mergeFunction) ` 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, K, U> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, U>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> keyMapper, https://developer.android.com/reference/java/util/function/Function<? super T, ? extends U> valueMapper) ` 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> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Set<T>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toSet()() ` Returns a `Collector` that accumulates the input elements into a new `Set`. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/List<T>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toUnmodifiableList()() ` Returns a `Collector` that accumulates the input elements into an [unmodifiable List](https://developer.android.com/reference/java/util/List.html#unmodifiable) in encounter order. |
| ` static <T, K, U> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, U>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toUnmodifiableMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> keyMapper, https://developer.android.com/reference/java/util/function/Function<? super T, ? extends U> valueMapper, https://developer.android.com/reference/java/util/function/BinaryOperator<U> mergeFunction) ` Returns a `Collector` that accumulates the input elements into an [unmodifiable Map](https://developer.android.com/reference/java/util/Map.html#unmodifiable), whose keys and values are the result of applying the provided mapping functions to the input elements. |
| ` static <T, K, U> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, U>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toUnmodifiableMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>)(https://developer.android.com/reference/java/util/function/Function<? super T, ? extends K> keyMapper, https://developer.android.com/reference/java/util/function/Function<? super T, ? extends U> valueMapper) ` Returns a `Collector` that accumulates the input elements into an [unmodifiable Map](https://developer.android.com/reference/java/util/Map.html#unmodifiable), whose keys and values are the result of applying the provided mapping functions to the input elements. |
| ` static <T> https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Set<T>>` | ` https://developer.android.com/reference/java/util/stream/Collectors#toUnmodifiableSet()() ` Returns a `Collector` that accumulates the input elements into an [unmodifiable Set](https://developer.android.com/reference/java/util/Set.html#unmodifiable). |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public methods

### averagingDouble

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Double> averagingDouble (ToDoubleFunction<? super T> mapper)
```

Returns a `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`.

<br />

##### Implementation Note:

- The `double` format can represent all consecutive integers in the range -2^53^ to 2^53^. If the pipeline has more than 2^53^ values, the divisor in the average computation will saturate at 2^53^, leading to additional numerical errors.

| Parameters ||
|---|---|
| `mapper` | `ToDoubleFunction`: a function extracting the property to be averaged <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Double>` | a `Collector` that produces the arithmetic mean of a derived property <br /> |

### averagingInt

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Double> averagingInt (ToIntFunction<? super T> mapper)
```

Returns a `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.

<br />

| Parameters ||
|---|---|
| `mapper` | `ToIntFunction`: a function extracting the property to be averaged <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Double>` | a `Collector` that produces the arithmetic mean of a derived property <br /> |

### averagingLong

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Double> averagingLong (ToLongFunction<? super T> mapper)
```

Returns a `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.

<br />

| Parameters ||
|---|---|
| `mapper` | `ToLongFunction`: a function extracting the property to be averaged <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Double>` | a `Collector` that produces the arithmetic mean of a derived property <br /> |

### collectingAndThen

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, A, RR> collectingAndThen (Collector<T, A, R> downstream, 
                Function<R, RR> finisher)
```

Adapts a `Collector` to perform an additional finishing transformation. For example, one could adapt the `https://developer.android.com/reference/java/util/stream/Collectors#toList()` collector to always produce an immutable list with:

    List<String> list = people.stream().collect(
      collectingAndThen(toList(),
                        Collections::unmodifiableList));

<br />

<br />

| Parameters ||
|---|---|
| `downstream` | `Collector`: a collector <br /> |
| `finisher` | `Function`: a function to be applied to the final result of the downstream collector <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, A, RR>` | a collector which performs the action of the downstream collector, followed by an additional finishing step <br /> |

### counting

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Long> counting ()
```

Returns a `Collector` accepting elements of type `T` that counts the number of input elements. If no elements are present, the result is 0.

<br />

##### Implementation Requirements:

- This produces a result equivalent to:

      reducing(0L, e -> 1L, Long::sum)

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Long>` | a `Collector` that counts the input elements <br /> |

### filtering

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, R> filtering (Predicate<? super T> predicate, 
                Collector<? super T, A, R> downstream)
```

Adapts a `Collector` to one accepting elements of the same type `T` by applying the predicate to each input element and only accumulating if the predicate returns `true`.

<br />

##### API Note:

- The `filtering()` collectors are most useful when used in a multi-level reduction, such as downstream of a `groupingBy` or `partitioningBy`. For example, given a stream of `Employee`, to accumulate the employees in each department that have a salary above a certain threshold:

      Map<Department, Set<Employee>> wellPaidEmployeesByDepartment
        = employees.stream().collect(
          groupingBy(Employee::getDepartment,
                     filtering(e -> e.getSalary() > 2000,
                               toSet())));

  A filtering collector differs from a stream's `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 empty `Set`. If a stream `filter()` operation were done instead, there would be no mapping for that department at all.

| Parameters ||
|---|---|
| `predicate` | `Predicate`: a predicate to be applied to the input elements <br /> |
| `downstream` | `Collector`: a collector which will accept values that match the predicate <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, R>` | a collector which applies the predicate to the input elements and provides matching elements to the downstream collector <br /> |

### flatMapping

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, R> flatMapping (Function<? super T, ? extends Stream<? extends U>> mapper, 
                Collector<? super U, A, R> downstream)
```

Adapts a `Collector` accepting elements of type `U` to one accepting elements of type `T` by applying a flat mapping function to each input element before accumulation. The flat mapping function maps an input element to a `https://developer.android.com/reference/java/util/stream/Stream` covering zero or more output elements that are then accumulated downstream. Each mapped stream is `https://developer.android.com/reference/java/util/stream/BaseStream#close()` after its contents have been placed downstream. (If a mapped stream is `null` an empty stream is used, instead.)

<br />

##### API Note:

- The `flatMapping()` collectors are most useful when used in a multi-level reduction, such as downstream of a `groupingBy` or `partitioningBy`. For example, given a stream of `Order`, 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())));

| Parameters ||
|---|---|
| `mapper` | `Function`: a function to be applied to the input elements, which returns a stream of results <br /> |
| `downstream` | `Collector`: a collector which will receive the elements of the stream returned by mapper <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, R>` | a collector which applies the mapping function to the input elements and provides the flat mapped results to the downstream collector <br /> |

### groupingBy

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, M> groupingBy (Function<? super T, ? extends K> classifier, 
                Supplier<M> mapFactory, 
                Collector<? super T, A, D> downstream)
```

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`. 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())));

<br />

<br />

##### Implementation Note:

- The returned `Collector` is not concurrent. For parallel stream pipelines, the `combiner` function 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, using `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Supplier<M>,%20java.util.stream.Collector<?%20super%20T,A,D>)` may offer better parallel performance.

| Parameters ||
|---|---|
| `classifier` | `Function`: a classifier function mapping input elements to keys <br /> |
| `mapFactory` | `Supplier`: a supplier providing a new empty `Map` into which the results will be inserted <br /> |
| `downstream` | `Collector`: a `Collector` implementing the downstream reduction <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, M>` | a `Collector` implementing the cascaded group-by operation <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.stream.Collector<?%20super%20T,A,D>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Supplier<M>,%20java.util.stream.Collector<?%20super%20T,A,D>)`

### groupingBy

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Map<K, List<T>>> groupingBy (Function<? super T, ? extends K> classifier)
```

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`.

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 `List`s 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.

<br />

##### Implementation Note:

- The returned `Collector` is not concurrent. For parallel stream pipelines, the `combiner` function 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 resulting `Map` collector is not required, using `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>)` may offer better parallel performance.

##### Implementation Requirements:

- This produces a result similar to:

      groupingBy(classifier, toList());

| Parameters ||
|---|---|
| `classifier` | `Function`: the classifier function mapping input elements to keys <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, https://developer.android.com/reference/java/util/List<T>>>` | a `Collector` implementing the group-by operation <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.stream.Collector<?%20super%20T,A,D>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Supplier<M>,%20java.util.stream.Collector<?%20super%20T,A,D>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>)`

### groupingBy

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Map<K, D>> groupingBy (Function<? super T, ? extends K> classifier, 
                Collector<? super T, A, D> downstream)
```

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`.

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())));

<br />

<br />

##### Implementation Note:

- The returned `Collector` is not concurrent. For parallel stream pipelines, the `combiner` function 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, using `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.stream.Collector<?%20super%20T,A,D>)` may offer better parallel performance.

| Parameters ||
|---|---|
| `classifier` | `Function`: a classifier function mapping input elements to keys <br /> |
| `downstream` | `Collector`: a `Collector` implementing the downstream reduction <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, D>>` | a `Collector` implementing the cascaded group-by operation <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Supplier<M>,%20java.util.stream.Collector<?%20super%20T,A,D>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.stream.Collector<?%20super%20T,A,D>)`

### groupingByConcurrent

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, M> groupingByConcurrent (Function<? super T, ? extends K> classifier, 
                Supplier<M> mapFactory, 
                Collector<? super T, A, D> downstream)
```

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`. The `ConcurrentMap` produced by the Collector is created with the supplied factory function.

This is a `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#CONCURRENT` and `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#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 `ConcurrentMap<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())));

<br />

<br />

| Parameters ||
|---|---|
| `classifier` | `Function`: a classifier function mapping input elements to keys <br /> |
| `mapFactory` | `Supplier`: a supplier providing a new empty `ConcurrentMap` into which the results will be inserted <br /> |
| `downstream` | `Collector`: a `Collector` implementing the downstream reduction <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, M>` | a concurrent, unordered `Collector` implementing the cascaded group-by operation <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.stream.Collector<?%20super%20T,A,D>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Supplier<M>,%20java.util.stream.Collector<?%20super%20T,A,D>)`

### groupingByConcurrent

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, ConcurrentMap<K, D>> groupingByConcurrent (Function<? super T, ? extends K> classifier, 
                Collector<? super T, A, D> downstream)
```

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`.

This is a `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#CONCURRENT` and `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#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 `ConcurrentMap<K, D>`.

There are no guarantees on the type, mutability, or serializability of the `ConcurrentMap` returned.

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())));

<br />

<br />

| Parameters ||
|---|---|
| `classifier` | `Function`: a classifier function mapping input elements to keys <br /> |
| `downstream` | `Collector`: a `Collector` implementing the downstream reduction <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/concurrent/ConcurrentMap<K, D>>` | a concurrent, unordered `Collector` implementing the cascaded group-by operation <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.stream.Collector<?%20super%20T,A,D>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Supplier<M>,%20java.util.stream.Collector<?%20super%20T,A,D>)`

### groupingByConcurrent

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, ConcurrentMap<K, List<T>>> groupingByConcurrent (Function<? super T, ? extends K> classifier)
```

Returns a concurrent `Collector` implementing a "group by" operation on input elements of type `T`, grouping elements according to a classification function.

This is a `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#CONCURRENT` and `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#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 `List`s 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 `ConcurrentMap` or `List` objects returned, or of the thread-safety of the `List` objects returned.

<br />

##### Implementation Requirements:

- This produces a result similar to:

      groupingByConcurrent(classifier, toList());

| Parameters ||
|---|---|
| `classifier` | `Function`: a classifier function mapping input elements to keys <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/concurrent/ConcurrentMap<K, https://developer.android.com/reference/java/util/List<T>>>` | a concurrent, unordered `Collector` implementing the group-by operation <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#groupingBy(java.util.function.Function<?%20super%20T,?%20extends%20K>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.stream.Collector<?%20super%20T,A,D>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#groupingByConcurrent(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Supplier<M>,%20java.util.stream.Collector<?%20super%20T,A,D>)`

### joining

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<CharSequence, ?, String> joining (CharSequence delimiter, 
                CharSequence prefix, 
                CharSequence suffix)
```

Returns a `Collector` that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.

<br />

| Parameters ||
|---|---|
| `delimiter` | `CharSequence`: the delimiter to be used between each element <br /> |
| `prefix` | `CharSequence`: the sequence of characters to be used at the beginning of the joined result <br /> |
| `suffix` | `CharSequence`: the sequence of characters to be used at the end of the joined result <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<https://developer.android.com/reference/java/lang/CharSequence, ?, https://developer.android.com/reference/java/lang/String>` | A `Collector` which concatenates CharSequence elements, separated by the specified delimiter, in encounter order <br /> |

### joining

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<CharSequence, ?, String> joining (CharSequence delimiter)
```

Returns a `Collector` that concatenates the input elements, separated by the specified delimiter, in encounter order.

<br />

| Parameters ||
|---|---|
| `delimiter` | `CharSequence`: the delimiter to be used between each element <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<https://developer.android.com/reference/java/lang/CharSequence, ?, https://developer.android.com/reference/java/lang/String>` | A `Collector` which concatenates CharSequence elements, separated by the specified delimiter, in encounter order <br /> |

### joining

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<CharSequence, ?, String> joining ()
```

Returns a `Collector` that concatenates the input elements into a `String`, in encounter order.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<https://developer.android.com/reference/java/lang/CharSequence, ?, https://developer.android.com/reference/java/lang/String>` | a `Collector` that concatenates the input elements into a `String`, in encounter order <br /> |

### mapping

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, R> mapping (Function<? super T, ? extends U> mapper, 
                Collector<? super U, A, R> downstream)
```

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.

<br />

##### API Note:

- The `mapping()` collectors are most useful when used in a multi-level reduction, such as downstream of a `groupingBy` or `partitioningBy`. For example, given a stream of `Person`, 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())));

| Parameters ||
|---|---|
| `mapper` | `Function`: a function to be applied to the input elements <br /> |
| `downstream` | `Collector`: a collector which will accept mapped values <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, R>` | a collector which applies the mapping function to the input elements and provides the mapped results to the downstream collector <br /> |

### maxBy

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Optional<T>> maxBy (Comparator<? super T> comparator)
```

Returns a `Collector` that produces the maximal element according to a given `Comparator`, described as an `Optional<T>`.

<br />

##### Implementation Requirements:

- This produces a result equivalent to:

      reducing(BinaryOperator.maxBy(comparator))

| Parameters ||
|---|---|
| `comparator` | `Comparator`: a `Comparator` for comparing elements <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Optional<T>>` | a `Collector` that produces the maximal value <br /> |

### minBy

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Optional<T>> minBy (Comparator<? super T> comparator)
```

Returns a `Collector` that produces the minimal element according to a given `Comparator`, described as an `Optional<T>`.

<br />

##### Implementation Requirements:

- This produces a result equivalent to:

      reducing(BinaryOperator.minBy(comparator))

| Parameters ||
|---|---|
| `comparator` | `Comparator`: a `Comparator` for comparing elements <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Optional<T>>` | a `Collector` that produces the minimal value <br /> |

### partitioningBy

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Map<Boolean, D>> partitioningBy (Predicate<? super T> predicate, 
                Collector<? super T, A, D> downstream)
```

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.

The returned `Map` always contains mappings for both `false` and `true` keys. There are no guarantees on the type, mutability, serializability, or thread-safety of the `Map` returned.

<br />

##### 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.

| Parameters ||
|---|---|
| `predicate` | `Predicate`: a predicate used for classifying input elements <br /> |
| `downstream` | `Collector`: a `Collector` implementing the downstream reduction <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/Boolean, D>>` | a `Collector` implementing the cascaded partitioning operation <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#partitioningBy(java.util.function.Predicate<?%20super%20T>)`

### partitioningBy

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Map<Boolean, List<T>>> partitioningBy (Predicate<? super T> predicate)
```

Returns a `Collector` which partitions the input elements according to a `Predicate`, and organizes them into a `Map<Boolean, List<T>>`. The returned `Map` always contains mappings for both `false` and `true` keys. There are no guarantees on the type, mutability, serializability, or thread-safety of the `Map` or `List` returned.

<br />

##### API Note:

- If a partition has no elements, its value in the result Map will be an empty List.

| Parameters ||
|---|---|
| `predicate` | `Predicate`: a predicate used for classifying input elements <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/Boolean, https://developer.android.com/reference/java/util/List<T>>>` | a `Collector` implementing the partitioning operation <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#partitioningBy(java.util.function.Predicate<?%20super%20T>,%20java.util.stream.Collector<?%20super%20T,A,D>)`

### reducing

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Optional<T>> reducing (BinaryOperator<T> op)
```

Returns a `Collector` which performs a reduction of its input elements under a specified `BinaryOperator`. The result is described as an `Optional<T>`.

<br />

##### API Note:

- The `reducing()` collectors are most useful when used in a multi-level reduction, downstream of `groupingBy` or `partitioningBy`. To perform a simple reduction on a stream, use `https://developer.android.com/reference/java/util/stream/Stream#reduce(java.util.function.BinaryOperator<T>)` 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))));

| Parameters ||
|---|---|
| `op` | `BinaryOperator`: a `BinaryOperator<T>` used to reduce the input elements <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Optional<T>>` | a `Collector` which implements the reduction operation <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#reducing(T,%20java.util.function.BinaryOperator<T>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#reducing(U,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)`

### reducing

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, U> reducing (U identity, 
                Function<? super T, ? extends U> mapper, 
                BinaryOperator<U> op)
```

Returns a `Collector` which performs a reduction of its input elements under a specified mapping function and `BinaryOperator`. This is a generalization of `https://developer.android.com/reference/java/util/stream/Collectors#reducing(T,%20java.util.function.BinaryOperator<T>)` which allows a transformation of the elements before reduction.

<br />

##### API Note:

- The `reducing()` collectors are most useful when used in a multi-level reduction, downstream of `groupingBy` or `partitioningBy`. To perform a simple map-reduce on a stream, use `https://developer.android.com/reference/java/util/stream/Stream#map(java.util.function.Function<?%20super%20T,?%20extends%20R>)` and `https://developer.android.com/reference/java/util/stream/Stream#reduce(T,%20java.util.function.BinaryOperator<T>)` 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))));

| Parameters ||
|---|---|
| `identity` | `U`: the identity value for the reduction (also, the value that is returned when there are no input elements) <br /> |
| `mapper` | `Function`: a mapping function to apply to each input value <br /> |
| `op` | `BinaryOperator`: a `BinaryOperator<U>` used to reduce the mapped values <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, U>` | a `Collector` implementing the map-reduce operation <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#reducing(T,%20java.util.function.BinaryOperator<T>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#reducing(java.util.function.BinaryOperator<T>)`

### reducing

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, T> reducing (T identity, 
                BinaryOperator<T> op)
```

Returns a `Collector` which performs a reduction of its input elements under a specified `BinaryOperator` using the provided identity.

<br />

##### API Note:

- The `reducing()` collectors are most useful when used in a multi-level reduction, downstream of `groupingBy` or `partitioningBy`. To perform a simple reduction on a stream, use `https://developer.android.com/reference/java/util/stream/Stream#reduce(T,%20java.util.function.BinaryOperator<T>)` instead.

| Parameters ||
|---|---|
| `identity` | `T`: the identity value for the reduction (also, the value that is returned when there are no input elements) <br /> |
| `op` | `BinaryOperator`: a `BinaryOperator<T>` used to reduce the input elements <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, T>` | a `Collector` which implements the reduction operation <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#reducing(java.util.function.BinaryOperator<T>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#reducing(U,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)`

### summarizingDouble

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, DoubleSummaryStatistics> summarizingDouble (ToDoubleFunction<? super T> mapper)
```

Returns a `Collector` which applies an `double`-producing mapping function to each input element, and returns summary statistics for the resulting values.

<br />

| Parameters ||
|---|---|
| `mapper` | `ToDoubleFunction`: a mapping function to apply to each element <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/DoubleSummaryStatistics>` | a `Collector` implementing the summary-statistics reduction <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#summarizingLong(java.util.function.ToLongFunction<?%20super%20T>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#summarizingInt(java.util.function.ToIntFunction<?%20super%20T>)`

### summarizingInt

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, IntSummaryStatistics> summarizingInt (ToIntFunction<? super T> mapper)
```

Returns a `Collector` which applies an `int`-producing mapping function to each input element, and returns summary statistics for the resulting values.

<br />

| Parameters ||
|---|---|
| `mapper` | `ToIntFunction`: a mapping function to apply to each element <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/IntSummaryStatistics>` | a `Collector` implementing the summary-statistics reduction <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#summarizingDouble(java.util.function.ToDoubleFunction<?%20super%20T>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#summarizingLong(java.util.function.ToLongFunction<?%20super%20T>)`

### summarizingLong

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, LongSummaryStatistics> summarizingLong (ToLongFunction<? super T> mapper)
```

Returns a `Collector` which applies an `long`-producing mapping function to each input element, and returns summary statistics for the resulting values.

<br />

| Parameters ||
|---|---|
| `mapper` | `ToLongFunction`: the mapping function to apply to each element <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/LongSummaryStatistics>` | a `Collector` implementing the summary-statistics reduction <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#summarizingDouble(java.util.function.ToDoubleFunction<?%20super%20T>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#summarizingInt(java.util.function.ToIntFunction<?%20super%20T>)`

### summingDouble

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Double> summingDouble (ToDoubleFunction<? super T> mapper)
```

Returns a `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`.

<br />

| Parameters ||
|---|---|
| `mapper` | `ToDoubleFunction`: a function extracting the property to be summed <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Double>` | a `Collector` that produces the sum of a derived property <br /> |

### summingInt

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Integer> summingInt (ToIntFunction<? super T> mapper)
```

Returns a `Collector` that produces the sum of an integer-valued function applied to the input elements. If no elements are present, the result is 0.

<br />

| Parameters ||
|---|---|
| `mapper` | `ToIntFunction`: a function extracting the property to be summed <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Integer>` | a `Collector` that produces the sum of a derived property <br /> |

### summingLong

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Long> summingLong (ToLongFunction<? super T> mapper)
```

Returns a `Collector` that produces the sum of a long-valued function applied to the input elements. If no elements are present, the result is 0.

<br />

| Parameters ||
|---|---|
| `mapper` | `ToLongFunction`: a function extracting the property to be summed <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/lang/Long>` | a `Collector` that produces the sum of a derived property <br /> |

### teeing

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, R> teeing (Collector<? super T, ?, R1> downstream1, 
                Collector<? super T, ?, R2> downstream2, 
                BiFunction<? super R1, ? super R2, R> merger)
```

Returns a `Collector` that is a composite of two downstream collectors. Every element passed to the resulting collector is processed by both downstream collectors, then their results are merged using the specified merge function into the final result.

The resulting collector functions do the following:

- supplier: creates a result container that contains result containers obtained by calling each collector's supplier
- accumulator: calls each collector's accumulator with its result container and the input element
- combiner: calls each collector's combiner with two result containers
- finisher: calls each collector's finisher with its result container, then calls the supplied merger and returns its result.

The resulting collector is `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#UNORDERED` if both downstream collectors are unordered and `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#CONCURRENT` if both downstream collectors are concurrent.

<br />

| Parameters ||
|---|---|
| `downstream1` | `Collector`: the first downstream collector <br /> |
| `downstream2` | `Collector`: the second downstream collector <br /> |
| `merger` | `BiFunction`: the function which merges two results into the single one <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, R>` | a `Collector` which aggregates the results of two supplied collectors. <br /> |

### toCollection

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, C> toCollection (Supplier<C> collectionFactory)
```

Returns a `Collector` that accumulates the input elements into a new `Collection`, in encounter order. The `Collection` is created by the provided factory.

<br />

| Parameters ||
|---|---|
| `collectionFactory` | `Supplier`: a supplier providing a new empty `Collection` into which the results will be inserted <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, C>` | a `Collector` which collects all the input elements into a `Collection`, in encounter order <br /> |

### toConcurrentMap

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, ConcurrentMap<K, U>> toConcurrentMap (Function<? super T, ? extends K> keyMapper, 
                Function<? super T, ? extends U> valueMapper)
```

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.

If the mapped keys contain duplicates (according to `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)`), an `IllegalStateException` is thrown when the collection operation is performed. If the mapped keys may have duplicates, use `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)` instead.

There are no guarantees on the type, mutability, or serializability of the `ConcurrentMap` returned.

<br />

##### API Note:

- It is common for either the key or the value to be the input elements. In this case, the utility method `https://developer.android.com/reference/java/util/function/Function#identity()` may be helpful. For example, the following produces a `ConcurrentMap` mapping students to their grade point average:

      ConcurrentMap<Student, Double> studentToGPA
        = students.stream().collect(
          toConcurrentMap(Function.identity(),
                          student -> computeGPA(student)));

  And the following produces a `ConcurrentMap` mapping a unique identifier to students:

      ConcurrentMap<String, Student> studentIdToStudent
        = students.stream().collect(
          toConcurrentMap(Student::getId,
                          Function.identity()));

  This is a `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#CONCURRENT` and `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#UNORDERED` Collector.

| Parameters ||
|---|---|
| `keyMapper` | `Function`: the mapping function to produce keys <br /> |
| `valueMapper` | `Function`: the mapping function to produce values <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/concurrent/ConcurrentMap<K, U>>` | a concurrent, unordered `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 <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>,%20java.util.function.Supplier<M>)`

### toConcurrentMap

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, M> toConcurrentMap (Function<? super T, ? extends K> keyMapper, 
                Function<? super T, ? extends U> valueMapper, 
                BinaryOperator<U> mergeFunction, 
                Supplier<M> mapFactory)
```

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.

If the mapped keys contain duplicates (according to `https://developer.android.com/reference/java/lang/Object#equals(java.lang.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 `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#CONCURRENT` and `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#UNORDERED` Collector.

<br />

| Parameters ||
|---|---|
| `keyMapper` | `Function`: a mapping function to produce keys <br /> |
| `valueMapper` | `Function`: a mapping function to produce values <br /> |
| `mergeFunction` | `BinaryOperator`: a merge function, used to resolve collisions between values associated with the same key, as supplied to `https://developer.android.com/reference/java/util/Map#merge(K,%20V,%20java.util.function.BiFunction<?%20super%20V,?%20super%20V,?%20extends%20V>)` <br /> |
| `mapFactory` | `Supplier`: a supplier providing a new empty `ConcurrentMap` into which the results will be inserted <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, M>` | a concurrent, unordered `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 <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>,%20java.util.function.Supplier<M>)`

### toConcurrentMap

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, ConcurrentMap<K, U>> toConcurrentMap (Function<? super T, ? extends K> keyMapper, 
                Function<? super T, ? extends U> valueMapper, 
                BinaryOperator<U> mergeFunction)
```

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.

If the mapped keys contain duplicates (according to `https://developer.android.com/reference/java/lang/Object#equals(java.lang.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 `ConcurrentMap` returned.

<br />

##### API Note:

- There are multiple ways to deal with collisions between multiple elements mapping to the same key. The other forms of `toConcurrentMap` simply use a merge function that throws unconditionally, but you can easily write more flexible merge policies. For example, if you have a stream of `Person`, 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 a `ConcurrentMap` mapping 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 `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#CONCURRENT` and `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#UNORDERED` Collector.

| Parameters ||
|---|---|
| `keyMapper` | `Function`: a mapping function to produce keys <br /> |
| `valueMapper` | `Function`: a mapping function to produce values <br /> |
| `mergeFunction` | `BinaryOperator`: a merge function, used to resolve collisions between values associated with the same key, as supplied to `https://developer.android.com/reference/java/util/Map#merge(K,%20V,%20java.util.function.BiFunction<?%20super%20V,?%20super%20V,?%20extends%20V>)` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/concurrent/ConcurrentMap<K, U>>` | a concurrent, unordered `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 <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>,%20java.util.function.Supplier<M>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)`

### toList

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, List<T>> toList ()
```

Returns a `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 `https://developer.android.com/reference/java/util/stream/Collectors#toCollection(java.util.function.Supplier<C>)`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/List<T>>` | a `Collector` which collects all the input elements into a `List`, in encounter order <br /> |

### toMap

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, M> toMap (Function<? super T, ? extends K> keyMapper, 
                Function<? super T, ? extends U> valueMapper, 
                BinaryOperator<U> mergeFunction, 
                Supplier<M> mapFactory)
```

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.

If the mapped keys contain duplicates (according to `https://developer.android.com/reference/java/lang/Object#equals(java.lang.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.

<br />

##### Implementation Note:

- The returned `Collector` is not concurrent. For parallel stream pipelines, the `combiner` function 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 the `Map` in encounter order, using `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>,%20java.util.function.Supplier<M>)` may offer better parallel performance.

| Parameters ||
|---|---|
| `keyMapper` | `Function`: a mapping function to produce keys <br /> |
| `valueMapper` | `Function`: a mapping function to produce values <br /> |
| `mergeFunction` | `BinaryOperator`: a merge function, used to resolve collisions between values associated with the same key, as supplied to `https://developer.android.com/reference/java/util/Map#merge(K,%20V,%20java.util.function.BiFunction<?%20super%20V,?%20super%20V,?%20extends%20V>)` <br /> |
| `mapFactory` | `Supplier`: a supplier providing a new empty `Map` into which the results will be inserted <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, M>` | a `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 <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>,%20java.util.function.Supplier<M>)`

### toMap

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Map<K, U>> toMap (Function<? super T, ? extends K> keyMapper, 
                Function<? super T, ? extends U> valueMapper, 
                BinaryOperator<U> mergeFunction)
```

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.

If the mapped keys contain duplicates (according to `https://developer.android.com/reference/java/lang/Object#equals(java.lang.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 `Map` returned.

<br />

##### API Note:

- There are multiple ways to deal with collisions between multiple elements mapping to the same key. The other forms of `toMap` simply use a merge function that throws unconditionally, but you can easily write more flexible merge policies. For example, if you have a stream of `Person`, 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 a `Map` mapping 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 `Collector` is not concurrent. For parallel stream pipelines, the `combiner` function 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 the `Map` in encounter order, using `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)` may offer better parallel performance.

| Parameters ||
|---|---|
| `keyMapper` | `Function`: a mapping function to produce keys <br /> |
| `valueMapper` | `Function`: a mapping function to produce values <br /> |
| `mergeFunction` | `BinaryOperator`: a merge function, used to resolve collisions between values associated with the same key, as supplied to `https://developer.android.com/reference/java/util/Map#merge(K,%20V,%20java.util.function.BiFunction<?%20super%20V,?%20super%20V,?%20extends%20V>)` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, U>>` | a `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 <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>,%20java.util.function.Supplier<M>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)`

### toMap

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Map<K, U>> toMap (Function<? super T, ? extends K> keyMapper, 
                Function<? super T, ? extends U> valueMapper)
```

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.

If the mapped keys contain duplicates (according to `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)`), an `IllegalStateException` is thrown when the collection operation is performed. If the mapped keys might have duplicates, use `https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)` instead.

There are no guarantees on the type, mutability, serializability, or thread-safety of the `Map` returned.

<br />

##### API Note:

- It is common for either the key or the value to be the input elements. In this case, the utility method `https://developer.android.com/reference/java/util/function/Function#identity()` may be helpful. For example, the following produces a `Map` mapping students to their grade point average:

      Map<Student, Double> studentToGPA
        = students.stream().collect(
          toMap(Function.identity(),
                student -> computeGPA(student)));

  And the following produces a `Map` mapping a unique identifier to students:

      Map<String, Student> studentIdToStudent
        = students.stream().collect(
          toMap(Student::getId,
                Function.identity()));

##### Implementation Note:

- The returned `Collector` is not concurrent. For parallel stream pipelines, the `combiner` function 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 the `Map` in encounter order, using `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>)` may offer better parallel performance.

| Parameters ||
|---|---|
| `keyMapper` | `Function`: a mapping function to produce keys <br /> |
| `valueMapper` | `Function`: a mapping function to produce values <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, U>>` | a `Collector` which collects elements into a `Map` whose keys and values are the result of applying mapping functions to the input elements <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>,%20java.util.function.Supplier<M>)`
- `https://developer.android.com/reference/java/util/stream/Collectors#toConcurrentMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>)`

### toSet

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Set<T>> toSet ()
```

Returns a `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 `https://developer.android.com/reference/java/util/stream/Collectors#toCollection(java.util.function.Supplier<C>)`.

This is an `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#UNORDERED` Collector.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Set<T>>` | a `Collector` which collects all the input elements into a `Set` <br /> |

### toUnmodifiableList

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, List<T>> toUnmodifiableList ()
```

Returns a `Collector` that accumulates the input elements into an [unmodifiable List](https://developer.android.com/reference/java/util/List.html#unmodifiable) in encounter order. The returned Collector disallows null values and will throw `NullPointerException` if it is presented with a null value.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/List<T>>` | a `Collector` that accumulates the input elements into an [unmodifiable List](https://developer.android.com/reference/java/util/List.html#unmodifiable) in encounter order <br /> |

### toUnmodifiableMap

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Map<K, U>> toUnmodifiableMap (Function<? super T, ? extends K> keyMapper, 
                Function<? super T, ? extends U> valueMapper, 
                BinaryOperator<U> mergeFunction)
```

Returns a `Collector` that accumulates the input elements into an [unmodifiable Map](https://developer.android.com/reference/java/util/Map.html#unmodifiable), 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 `https://developer.android.com/reference/java/lang/Object#equals(java.lang.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, `NullPointerException` will be thrown.

<br />

| Parameters ||
|---|---|
| `keyMapper` | `Function`: a mapping function to produce keys, must be non-null <br /> |
| `valueMapper` | `Function`: a mapping function to produce values, must be non-null <br /> |
| `mergeFunction` | `BinaryOperator`: a merge function, used to resolve collisions between values associated with the same key, as supplied to `https://developer.android.com/reference/java/util/Map#merge(K,%20V,%20java.util.function.BiFunction<?%20super%20V,?%20super%20V,?%20extends%20V>)`, must be non-null <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, U>>` | a `Collector` that accumulates the input elements into an [unmodifiable Map](https://developer.android.com/reference/java/util/Map.html#unmodifiable), whose keys and values are the result of applying the provided mapping functions to the input elements <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the keyMapper, valueMapper, or mergeFunction is null |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#toUnmodifiableMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>)`

### toUnmodifiableMap

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Map<K, U>> toUnmodifiableMap (Function<? super T, ? extends K> keyMapper, 
                Function<? super T, ? extends U> valueMapper)
```

Returns a `Collector` that accumulates the input elements into an [unmodifiable Map](https://developer.android.com/reference/java/util/Map.html#unmodifiable), 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 `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)`), an `IllegalStateException` is thrown when the collection operation is performed. If the mapped keys might have duplicates, use `https://developer.android.com/reference/java/util/stream/Collectors#toUnmodifiableMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)` to handle merging of the values.

The returned Collector disallows null keys and values. If either mapping function returns null, `NullPointerException` will be thrown.

<br />

| Parameters ||
|---|---|
| `keyMapper` | `Function`: a mapping function to produce keys, must be non-null <br /> |
| `valueMapper` | `Function`: a mapping function to produce values, must be non-null <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Map<K, U>>` | a `Collector` that accumulates the input elements into an [unmodifiable Map](https://developer.android.com/reference/java/util/Map.html#unmodifiable), whose keys and values are the result of applying the provided mapping functions to the input elements <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if either keyMapper or valueMapper is null |

**See also:**

- `https://developer.android.com/reference/java/util/stream/Collectors#toUnmodifiableMap(java.util.function.Function<?%20super%20T,?%20extends%20K>,%20java.util.function.Function<?%20super%20T,?%20extends%20U>,%20java.util.function.BinaryOperator<U>)`

### toUnmodifiableSet

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Collector<T, ?, Set<T>> toUnmodifiableSet ()
```

Returns a `Collector` that accumulates the input elements into an [unmodifiable Set](https://developer.android.com/reference/java/util/Set.html#unmodifiable). The returned Collector disallows null values and will throw `NullPointerException` if it is presented with a null value. If the input contains duplicate elements, an arbitrary element of the duplicates is preserved.

This is an `https://developer.android.com/reference/java/util/stream/Collector.Characteristics#UNORDERED` Collector.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/stream/Collector<T, ?, https://developer.android.com/reference/java/util/Set<T>>` | a `Collector` that accumulates the input elements into an [unmodifiable Set](https://developer.android.com/reference/java/util/Set.html#unmodifiable) <br /> |