Close

Java 8 Streams - LongStream.skip Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.LongStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.LongStreamLongStreamLogicBig

Method:

LongStream skip(long n)

This stateful intermediate operation returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream. If this stream contains fewer than n elements then an empty stream will be returned.

Examples


package com.logicbig.example.longstream;

import java.util.stream.LongStream;

public class SkipExample {

public static void main(String... args) {
LongStream.of(4, 7, 9, 11, 13, 17)
.skip(2)
.forEach(System.out::println);
}
}

Output

9
11
13
17




Parallel stream:

package com.logicbig.example.longstream;

import java.util.stream.LongStream;

public class SkipExample2 {

public static void main(String... args) {
LongStream.of(4, 7, 9, 11, 13, 17)
.parallel()
.skip(2)
.forEach(System.out::println);
}
}

Output

11
13
17
9




See Also