Collectors 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
實作 Collector 中實現了各種有用的約簡操作,例如將元素累積成集合、根據各種條件彙整元素等。
[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
- 繼承
- 屬性
備註
實作 Collector 中實現了各種有用的約簡操作,例如將元素累積成集合、根據各種條件彙整元素等。
以下是使用預定義收集器執行常見可變約簡任務的範例:
{@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));
}
新增於1.8版本。
Java 文件 java.util.stream.Collectors。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。
屬性
| 名稱 | Description |
|---|---|
| Class |
回傳此 |
| Handle |
底層 Android 實例的帳號。 (繼承來源 Object) |
| JniIdentityHashCode |
取得由互通執行時指派給此 Java 對等端的身份雜湊碼。 (繼承來源 Object) |
| JniManagedPeerState |
取得執行時最後指派的狀態旗標。 (繼承來源 JavaObject) |
| JniPeerMembers |
取得用於調用此 Java 節點成員的 JNI 元資料。 |
| PeerReference |
取得這個 Java 節點的 JNI 物件參考。 (繼承來源 Object) |
| ThresholdClass |
此 API 支援 Mono for Android 基礎架構,並非直接從你的程式碼中使用。 (繼承來源 Object) |
| ThresholdType |
此 API 支援 Mono for Android 基礎架構,並非直接從你的程式碼中使用。 (繼承來源 Object) |
方法
| 名稱 | Description |
|---|---|
| AveragingDouble(IToDoubleFunction) |
回傳 a |
| AveragingInt(IToIntFunction) |
回傳 a |
| AveragingLong(IToLongFunction) |
回傳 a |
| Clone() |
建立並回傳此物件的副本。 (繼承來源 Object) |
| CollectingAndThen(ICollector, IFunction) |
調整 a |
| Construct(JniObjectReference, JniObjectReferenceOptions) |
將此對等節點的建置委派給執行時的值管理器。 (繼承來源 JavaObject) |
| Counting() |
回傳一個 |
| Dispose() |
釋放該 Java 節點所持有的資源。 (繼承來源 Object) |
| Dispose(Boolean) |
釋放該 Java 節點所持有的資源。 (繼承來源 Object) |
| DisposeUnlessReferenced() |
請求值管理器處置此對等節點,除非其映射保留該受管理實例。 (繼承來源 JavaObject) |
| Equals(Object) |
測試另一個受管理節點是否參考相同的 Java 物件。 (繼承來源 JavaObject) |
| Equals(Object) |
表示是否有其他物體「等同」於此物。 (繼承來源 Object) |
| Filtering(IPredicate, ICollector) |
將 a |
| GetHashCode() |
回傳物件的雜湊碼值。 (繼承來源 Object) |
| GroupingBy(IFunction, ICollector) |
回傳對 |
| GroupingBy(IFunction, ISupplier, ICollector) |
回傳對 |
| GroupingBy(IFunction) |
回傳對 |
| GroupingByConcurrent(IFunction, ICollector) |
回傳一個並行 |
| GroupingByConcurrent(IFunction, ISupplier, ICollector) |
回傳一個並行 |
| GroupingByConcurrent(IFunction) |
回傳一個並行 |
| JavaFinalize() |
已淘汰.
當垃圾回收判定該物件不再有相關參考時,由垃圾回收器呼叫。 (繼承來源 Object) |
| Joining() |
回傳 a |
| Joining(ICharSequence, ICharSequence, ICharSequence) |
回傳 a |
| Joining(ICharSequence) |
回傳 a |
| Joining(String, String, String) |
回傳 a |
| Joining(String) |
回傳 a |
| Mapping(IFunction, ICollector) |
在累積前,對每個輸入元素套用映射函數,將 |
| MaxBy(IComparator) |
回傳 a |
| MinBy(IComparator) |
回傳 a |
| Notify() |
喚醒一個正在該物件監視器上等待的執行緒。 (繼承來源 Object) |
| NotifyAll() |
喚醒所有等待該物件監視器的執行緒。 (繼承來源 Object) |
| PartitioningBy(IPredicate, ICollector) |
回傳 a |
| PartitioningBy(IPredicate) |
回傳 a |
| Reducing(IBinaryOperator) |
回傳 a |
| Reducing(Object, IBinaryOperator) |
回傳 a |
| Reducing(Object, IFunction, IBinaryOperator) |
回傳 a |
| SetHandle(IntPtr, JniHandleOwnership) |
設定 Handle 屬性。 (繼承來源 Object) |
| SetPeerReference(JniObjectReference, JniObjectReferenceOptions) |
在控制區塊中儲存參考值,但不建立 JNI 參考副本。 (繼承來源 JavaObject) |
| SummarizingDouble(IToDoubleFunction) |
回傳 a |
| SummarizingInt(IToIntFunction) |
回傳 a |
| SummarizingLong(IToLongFunction) |
回傳 a |
| SummingDouble(IToDoubleFunction) |
回傳 a |
| SummingInt(IToIntFunction) |
回傳 a |
| SummingLong(IToLongFunction) |
回傳 a |
| Teeing(ICollector, ICollector, IBiFunction) |
回波 a |
| ToArray<T>() |
從這個 Java 陣列包裝器建立一個受管理陣列。 (繼承來源 Object) |
| ToCollection(ISupplier) |
回傳 a |
| ToConcurrentMap(IFunction, IFunction, IBinaryOperator, ISupplier) |
回傳一個並行 |
| ToConcurrentMap(IFunction, IFunction, IBinaryOperator) |
回傳一個並行 |
| ToConcurrentMap(IFunction, IFunction) |
回傳一個並行 |
| ToList() |
回傳 a |
| ToMap(IFunction, IFunction, IBinaryOperator, ISupplier) |
回傳 a |
| ToMap(IFunction, IFunction, IBinaryOperator) |
回傳 a |
| ToMap(IFunction, IFunction) |
回傳 a |
| ToSet() |
回傳 a |
| ToString() |
回傳物件的字串表示。 (繼承來源 Object) |
| ToUnmodifiableList() |
回傳 a |
| ToUnmodifiableMap(IFunction, IFunction, IBinaryOperator) |
回傳 a |
| ToUnmodifiableMap(IFunction, IFunction) |
回傳 a |
| ToUnmodifiableSet() |
回傳 |
| UnregisterFromRuntime() |
將此 Java 節點從互通執行時中取消註冊。 (繼承來源 Object) |
| Wait() |
使目前執行緒等待被喚醒,通常是透過 通知 或 中斷。 (繼承來源 Object) |
| Wait(Int64, Int32) |
使目前執行緒等待被喚醒(通常是透過 通知 或 中斷),或等待一定的實際時間過去。 (繼承來源 Object) |
| Wait(Int64) |
使目前執行緒等待被喚醒(通常是透過 通知 或 中斷),或等待一定的實際時間過去。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| IJavaPeerable.Disposed() |
標記此節點為處置,並以 |
| IJavaPeerable.Finalized() |
標記此節點為處置,並以 |
| IJavaPeerable.JniObjectReferenceControlBlock |
取得此對等端使用的原生控制區塊指標。 (繼承來源 JavaObject) |
| IJavaPeerable.SetJniIdentityHashCode(Int32) |
儲存執行時提供的身份雜湊碼。 (繼承來源 JavaObject) |
| IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) |
取代儲存的受管理對等狀態旗標。 (繼承來源 JavaObject) |
| IJavaPeerable.SetPeerReference(JniObjectReference) |
當引用無效時,更新對等節點並釋放已拋棄節點的控制區塊。 (繼承來源 JavaObject) |
擴充方法
| 名稱 | Description |
|---|---|
| GetJniTypeName(IJavaPeerable) |
取得實例 |
| JavaAs<TResult>(IJavaPeerable) |
試著強制 |
| JavaCast<TResult>(IJavaObject) |
執行 Android 執行時檢查型別轉換。 |
| JavaCast<TResult>(IJavaObject) |
重用相容的受管理對等端或取得請求型態的包裝器。 |
| TryJavaCast<TResult>(IJavaPeerable, TResult) |
試著強制 |