Java Streams - LongStream skip(long n) example








LongStream skip(long n) returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream.

Syntax

skip has the following syntax.

LongStream skip(long n)

Example

The following example shows how to use skip.

import java.util.stream.LongStream;

public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);

    b.skip(2).forEach(System.out::println);
  }
}

The code above generates the following result.