Close

Java 8 Streams - DoubleStream.skip Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.DoubleStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.DoubleStreamDoubleStreamLogicBig

Method:

DoubleStream 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.doublestream;

import java.util.stream.DoubleStream;

public class SkipExample {

public static void main(String... args) {

System.out.println("-- sequential --");
DoubleStream.of(1.0, 1.2, 2.0, 2.4, 3.0)
.skip(2)
.forEach(System.out::println);

System.out.println("-- parallel --");
DoubleStream.of(1.0, 1.2, 2.0, 2.4, 3.0)
.parallel()
.skip(2)
.forEach(System.out::println);

System.out.println("-- unordered parallel --");
DoubleStream.of(1.0, 1.2, 2.0, 2.4, 3.0)
.unordered()
.parallel()
.skip(2)
.forEach(System.out::println);
}
}

Output

-- sequential --
2.0
2.4
3.0
-- parallel --
2.4
3.0
2.0
-- unordered parallel --
2.4
2.0
3.0




package com.logicbig.example.doublestream;

import java.util.stream.DoubleStream;

public class SkipExample2 {

public static void main(String... args) {
long count = DoubleStream.of(1.0, 1.2, 2.0, 2.4, 3.0)
.skip(100)
.count();
System.out.println(count);
}
}

Output

0




See Also