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 |
實作 |
| 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) |
實作 |
| Counting() |
回傳一個 |
| Dispose() |
釋放該 Java 節點所持有的資源。 (繼承來源 Object) |
| Dispose(Boolean) |
釋放該 Java 節點所持有的資源。 (繼承來源 Object) |
| DisposeUnlessReferenced() |
實作 |
| Equals(Object) |
實作 |
| 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) |
實作 |
| 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() |
導致目前執行緒等待被喚醒,通常是透過 <em>通知</><em 或 em>中斷</em> 來喚醒。 (繼承來源 Object) |
| Wait(Int64, Int32) |
會讓目前執行緒等待喚醒,通常是透過 <em>通知</><em 或 em>中斷</em>,或是經過一定的真實時間。 (繼承來源 Object) |
| Wait(Int64) |
會讓目前執行緒等待喚醒,通常是透過 <em>通知</><em 或 em>中斷</em>,或是經過一定的真實時間。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| IJavaPeerable.Disposed() |
實作 |
| IJavaPeerable.Finalized() |
實作 |
| IJavaPeerable.JniObjectReferenceControlBlock |
實作 |
| IJavaPeerable.SetJniIdentityHashCode(Int32) |
實作 |
| IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) |
實作 |
| IJavaPeerable.SetPeerReference(JniObjectReference) |
實作 |
擴充方法
| 名稱 | Description |
|---|---|
| GetJniTypeName(IJavaPeerable) |
取得實例 |
| JavaAs<TResult>(IJavaPeerable) |
試著強制 |
| JavaCast<TResult>(IJavaObject) |
執行 Android 執行時檢查型別轉換。 |
| JavaCast<TResult>(IJavaObject) |
實作 |
| TryJavaCast<TResult>(IJavaPeerable, TResult) |
試著強制 |