Collectors.GroupingBy Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
GroupingBy(IFunction) |
Returns a |
GroupingBy(IFunction, ICollector) |
Returns a |
GroupingBy(IFunction, ISupplier, ICollector) |
Returns a |
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
.
[Android.Runtime.Register("groupingBy", "(Ljava/util/function/Function;)Ljava/util/stream/Collector;", "", ApiSince=24)]
[Java.Interop.JavaTypeParameters(new System.String[] { "T", "K" })]
public static Java.Util.Streams.ICollector? GroupingBy (Java.Util.Functions.IFunction? classifier);
[<Android.Runtime.Register("groupingBy", "(Ljava/util/function/Function;)Ljava/util/stream/Collector;", "", ApiSince=24)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T", "K" })>]
static member GroupingBy : Java.Util.Functions.IFunction -> Java.Util.Streams.ICollector
Parameters
- classifier
- IFunction
the classifier function mapping input elements to keys
Returns
a Collector
implementing the group-by operation
- Attributes
Remarks
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.
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.
Applies to
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
.
[Android.Runtime.Register("groupingBy", "(Ljava/util/function/Function;Ljava/util/stream/Collector;)Ljava/util/stream/Collector;", "", ApiSince=24)]
[Java.Interop.JavaTypeParameters(new System.String[] { "T", "K", "A", "D" })]
public static Java.Util.Streams.ICollector? GroupingBy (Java.Util.Functions.IFunction? classifier, Java.Util.Streams.ICollector? downstream);
[<Android.Runtime.Register("groupingBy", "(Ljava/util/function/Function;Ljava/util/stream/Collector;)Ljava/util/stream/Collector;", "", ApiSince=24)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T", "K", "A", "D" })>]
static member GroupingBy : Java.Util.Functions.IFunction * Java.Util.Streams.ICollector -> Java.Util.Streams.ICollector
Parameters
- classifier
- IFunction
a classifier function mapping input elements to keys
- downstream
- ICollector
a Collector
implementing the downstream reduction
Returns
a Collector
implementing the cascaded group-by operation
- Attributes
Remarks
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:
{@code
Map<City, Set<String>> namesByCity
= people.stream().collect(
groupingBy(Person::getCity,
mapping(Person::getLastName,
toSet())));
}
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.
Applies to
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
.
[Android.Runtime.Register("groupingBy", "(Ljava/util/function/Function;Ljava/util/function/Supplier;Ljava/util/stream/Collector;)Ljava/util/stream/Collector;", "", ApiSince=24)]
[Java.Interop.JavaTypeParameters(new System.String[] { "T", "K", "D", "A", "M extends java.util.Map<K, D>" })]
public static Java.Util.Streams.ICollector? GroupingBy (Java.Util.Functions.IFunction? classifier, Java.Util.Functions.ISupplier? mapFactory, Java.Util.Streams.ICollector? downstream);
[<Android.Runtime.Register("groupingBy", "(Ljava/util/function/Function;Ljava/util/function/Supplier;Ljava/util/stream/Collector;)Ljava/util/stream/Collector;", "", ApiSince=24)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T", "K", "D", "A", "M extends java.util.Map<K, D>" })>]
static member GroupingBy : Java.Util.Functions.IFunction * Java.Util.Functions.ISupplier * Java.Util.Streams.ICollector -> Java.Util.Streams.ICollector
Parameters
- classifier
- IFunction
a classifier function mapping input elements to keys
- mapFactory
- ISupplier
a supplier providing a new empty Map
into which the results will be inserted
- downstream
- ICollector
a Collector
implementing the downstream reduction
Returns
a Collector
implementing the cascaded group-by operation
- Attributes
Remarks
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:
{@code
Map<City, Set<String>> namesByCity
= people.stream().collect(
groupingBy(Person::getCity,
TreeMap::new,
mapping(Person::getLastName,
toSet())));
}
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.