What Java 17’s Stream SIZED Feature Means for skip() and limit()
Java 17 introduces a SIZED characteristic for streams that keeps skip() and limit() effective without traversing elements, altering the behavior of operations like peek() and requiring developers to adjust their code accordingly.
Introduction
Java 17, released on September 14, is a long‑term support (LTS) version that brings several changes, including a new SIZED characteristic for the
StreamAPI.
Java 17 Stream SIZED Feature
Starting with Java 17, a stream marked as SIZED retains its size information, so operations such as
skip()and
limit()remain effective during processing. This can change the observable behavior of a stream.
<code>long count = Stream.of(1, 2, 3, 4)
.skip(1)
.limit(2)
.peek(System.out::println)
.count();
System.out.println("count:\t" + count);
</code>In Java 8‑16 the
peekcall would print the values 2 and 3, but in Java 17 it prints nothing because the stream size is known in advance and the elements need not be traversed.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.