Compartilhar via


Collectors Class

Definition

Implementations of Collector that implement various useful reduction operations, such as accumulating elements into collections, summarizing elements according to various criteria, etc.

[Android.Runtime.Register("java/util/stream/Collectors", ApiSince=24, DoNotGenerateAcw=true)]
public sealed class Collectors : Java.Lang.Object
[<Android.Runtime.Register("java/util/stream/Collectors", ApiSince=24, DoNotGenerateAcw=true)>]
type Collectors = class
    inherit Object
Inheritance
Collectors
Attributes

Remarks

Implementations of 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:

{@code
            // 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));

            }

Added in 1.8.

Java documentation for java.util.stream.Collectors.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)
ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)

Methods

AveragingDouble(IToDoubleFunction)

Returns a Collector that produces the arithmetic mean of a double-valued function applied to the input elements.

AveragingInt(IToIntFunction)

Returns a Collector that produces the arithmetic mean of an integer-valued function applied to the input elements.

AveragingLong(IToLongFunction)

Returns a Collector that produces the arithmetic mean of a long-valued function applied to the input elements.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CollectingAndThen(ICollector, IFunction)

Adapts a Collector to perform an additional finishing transformation.

Counting()

Returns a Collector accepting elements of type T that counts the number of input elements.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
Filtering(IPredicate, ICollector)

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.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GroupingBy(IFunction, ICollector)

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.

GroupingBy(IFunction, ISupplier, ICollector)

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.

GroupingBy(IFunction)

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.

GroupingByConcurrent(IFunction, ICollector)

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.

GroupingByConcurrent(IFunction, ISupplier, ICollector)

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.

GroupingByConcurrent(IFunction)

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

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Joining()

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

Joining(ICharSequence, ICharSequence, ICharSequence)

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

Joining(ICharSequence)

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

Joining(String, String, String)

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

Joining(String)

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

Mapping(IFunction, ICollector)

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.

MaxBy(IComparator)

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

MinBy(IComparator)

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

Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
PartitioningBy(IPredicate, ICollector)

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.

PartitioningBy(IPredicate)

Returns a Collector which partitions the input elements according to a Predicate, and organizes them into a Map<Boolean, List<T>>.

Reducing(IBinaryOperator)

Returns a Collector which performs a reduction of its input elements under a specified BinaryOperator.

Reducing(Object, IBinaryOperator)

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

Reducing(Object, IFunction, IBinaryOperator)

Returns a Collector which performs a reduction of its input elements under a specified mapping function and BinaryOperator.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SummarizingDouble(IToDoubleFunction)

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

SummarizingInt(IToIntFunction)

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

SummarizingLong(IToLongFunction)

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

SummingDouble(IToDoubleFunction)

Returns a Collector that produces the sum of a double-valued function applied to the input elements.

SummingInt(IToIntFunction)

Returns a Collector that produces the sum of a integer-valued function applied to the input elements.

SummingLong(IToLongFunction)

Returns a Collector that produces the sum of a long-valued function applied to the input elements.

ToArray<T>() (Inherited from Object)
ToCollection(ISupplier)

Returns a Collector that accumulates the input elements into a new Collection, in encounter order.

ToConcurrentMap(IFunction, IFunction, IBinaryOperator, ISupplier)

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.

ToConcurrentMap(IFunction, IFunction, IBinaryOperator)

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.

ToConcurrentMap(IFunction, IFunction)

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.

ToList()

Returns a Collector that accumulates the input elements into a new List.

ToMap(IFunction, IFunction, IBinaryOperator, ISupplier)

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.

ToMap(IFunction, IFunction, IBinaryOperator)

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.

ToMap(IFunction, IFunction)

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.

ToSet()

Returns a Collector that accumulates the input elements into a new Set.

ToString()

Returns a string representation of the object.

(Inherited from Object)
ToUnmodifiableList()

Returns a Collector that accumulates the input elements into an unmodifiable List in encounter order.

ToUnmodifiableMap(IFunction, IFunction, IBinaryOperator)

Returns a Collector that accumulates the input elements into an unmodifiable Map, whose keys and values are the result of applying the provided mapping functions to the input elements.

ToUnmodifiableMap(IFunction, IFunction)

Returns a Collector that accumulates the input elements into an unmodifiable Map, whose keys and values are the result of applying the provided mapping functions to the input elements.

ToUnmodifiableSet()

Returns a Collector that accumulates the input elements into an unmodifiable Set.

UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to