Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b7N4ZDbUtA3ofqAqRV
15 lines
720 B
Java
15 lines
720 B
Java
import java.util.List;
|
|
import java.util.stream.Gatherers;
|
|
import java.util.stream.Stream;
|
|
|
|
/** Stream gatherers are final since Java 24 (JEP 485); on 21 the package does not contain them. */
|
|
public class GathererDemo {
|
|
public static void main(String[] args) {
|
|
System.out.println(Stream.of(1, 2, 3, 4, 5).gather(Gatherers.windowFixed(2)).toList());
|
|
System.out.println(Stream.of(1, 2, 3, 4).gather(Gatherers.windowSliding(3)).toList());
|
|
System.out.println(Stream.of(1, 2, 3, 4).gather(Gatherers.scan(() -> 0, Integer::sum)).toList());
|
|
List<String> out = Stream.of("a", "b", "c").gather(Gatherers.mapConcurrent(2, String::toUpperCase)).toList();
|
|
System.out.println(out);
|
|
}
|
|
}
|