Streams Zaawansowany

Use gatherers for custom intermediate stream operations.

✕ Java 8
// Sliding window: manual implementation
List<List<T>> windows = new ArrayList<>();
for (int i = 0; i <= list.size()-3; i++) {
    windows.add(
        list.subList(i, i + 3));
}
✓ Java 24+
var windows = stream
    .gather(
        Gatherers.windowSliding(3)
    )
    .toList();
Widzisz problem z tym kodem? Daj nam znać.
🧩

Composable

Gatherers compose with other stream operations.

📦

Built-in operations

windowFixed, windowSliding, fold, scan out of the box.

🔧

Extensible

Write custom gatherers for any intermediate transformation.

Stare podejście
Custom Collector
Nowoczesne podejście
gather()
Od JDK
24
Poziom trudności
Zaawansowany
Stream gatherers
Dostępne

Finalized in JDK 24 (JEP 485, March 2025).

Gatherers are a new intermediate stream operation that can express complex transformations like sliding windows, fixed-size groups, and scan operations that were impossible with standard stream ops.

Udostępnij 𝕏 🦋 in