IntStream skip() in Java
Last Updated :
21 Mar, 2018
IntStream skip(long n) 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.
Note : IntStream skip() is a stateful intermediate operation i.e, it may incorporate state from previously seen elements when processing new elements.
Syntax :
IntStream skip(long n)
Parameter : IntStream is a sequence of primitive int-valued elements. This is the int primitive specialization of Stream. n is the number of leading elements to skip.
Return Value : The function returns the new stream after discarding first n elements.
Exception : The function throws IllegalArgumentException if n is negative.
Example 1 :
import java.util.*;
import java.util.stream.IntStream;
class GFG {
public static void main(String[] args)
{
IntStream stream = IntStream.range( 5 , 12 );
stream.skip( 4 ).forEach(System.out::println);
}
}
|
Output :
9
10
11
Example 2 :
import java.util.*;
import java.util.stream.IntStream;
class GFG {
public static void main(String[] args)
{
IntStream stream = IntStream.range( 5 , 12 );
stream.parallel().skip( 4 ).forEach(System.out::println);
}
}
|
Output :
10
11
9
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...