Backend Development 2 min read

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.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
What Java 17’s Stream SIZED Feature Means for skip() and limit()

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

Stream

API.

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

peek

call 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.

JavalimitStreamJava17skipSIZED
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.