Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Java reference

Stream.skip()

Skips the first N elements of a stream.

Available since: Java 8

Syntax

Stream<T> skip(long n)

Parameters

ParameterTypeDescription
nlongHow many leading elements to skip.

Return value

Stream<T>The stream without its first `n` elements.

Examples

The second page of three elements:

void main() {
    List<Integer> items = List.of(1, 2, 3, 4, 5, 6, 7, 8);
    int page = 2, size = 3;
    IO.println(items.stream().skip((long) (page - 1) * size).limit(size).toList());
}

Output:

[4, 5, 6]

Notes

Skipping more elements than there are gives an empty stream, without an exception. To skip while a condition holds, use dropWhile().

See also

Related recipes

In the tutorial

  • Stream operations — The main Stream API operations — filter, map, sorted, distinct, limit, skip, count, reduce, anyMatch, findFirst and numeric streams.

Thanks for reading!

Donate to the site — we work hard for you.