Open In App

IntStream skip() in Java

Last Updated : 21 Mar, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

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 :




// Java code for IntStream skip() function
import java.util.*;
import java.util.stream.IntStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an IntStream of numbers [5, 6, .. 11]
        IntStream stream = IntStream.range(5, 12);
  
        // Using skip() to skip first 4 values in range
        // and displaying the rest of elements
        stream.skip(4).forEach(System.out::println);
    }
}


Output :

9
10
11

Example 2 :




// Java code for IntStream skip() function
import java.util.*;
import java.util.stream.IntStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an IntStream [5, 6, .. 11]
        IntStream stream = IntStream.range(5, 12);
  
        // Using parallel skip() to skip first 4 values in range
        // and displaying the rest of elements
        stream.parallel().skip(4).forEach(System.out::println);
    }
}


Output :

10
11
9


Similar Reads

IntStream iterator() in Java
IntStream iterator() returns an iterator for the elements of this stream. It is a terminal operation i.e, it may traverse the stream to produce a result or a side-effect. Syntax : PrimitiveIterator.OfInt iterator() Where, PrimitiveIterator.OfInt is an Iterator specialized for int values. Return Value : IntStream iterator() returns the element itera
2 min read
IntStream rangeClosed() in Java
IntStream rangeClosed(int startInclusive, int endInclusive) returns an IntStream from startInclusive (inclusive) to endInclusive (inclusive) by an incremental step of 1. Syntax : static IntStream rangeClosed(int startInclusive, int endInclusive) Parameters : IntStream : A sequence of primitive int-valued elements. startInclusive : The inclusive ini
1 min read
IntStream map(IntUnaryOperator mapper) in Java
IntStream map(IntUnaryOperator mapper) returns a stream consisting of the results of applying the given function to the elements of this stream. This is an intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output.
2 min read
IntStream findFirst() in Java
IntStream findFirst() returns an OptionalInt (a container object which may or may not contain a non-null value) describing the first element of this stream, or an empty OptionalInt if the stream is empty Syntax : OptionalInt findFirst() Where, OptionalInt is a container object which may or may not contain a non-null value and the function returns a
2 min read
IntStream parallel() in Java
IntStream parallel() is a method in java.util.stream.IntStream. This method returns a parallel IntStream, i.e, it may return itself, either because the stream was already present, or because the underlying stream state was modified to be parallel. IntStream parallel() is an intermediate operation. These operations are always lazy. Intermediate oper
2 min read
IntStream empty() in Java with examples
IntStream empty() is a method in java.util.stream.IntStream. This method returns an empty sequential IntStream. Syntax : static <T> Stream<T> empty() Where, T is the type of stream elements, and the function returns an empty sequential stream. Example 1 : Creating empty IntStream. // Java code for IntStream empty() import java.util.*; i
1 min read
IntStream distinct() in Java with examples
IntStream distinct() is a method in java.util.stream.IntStream. This method returns a stream consisting of the distinct elements. This is a stateful intermediate operation i.e, it may incorporate state from previously seen elements when processing new elements. Syntax : IntStream distinct() Where, IntStream is a sequence of primitive int-valued ele
2 min read
IntStream peek() in Java with examples
IntStream peek() is a method in java.util.stream.IntStream. The function returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream. Syntax : IntStream peek(IntConsumer action) Where, IntStream is a sequence of primitive int-valued elemen
3 min read
IntStream average() in Java with Examples
java.util.stream.IntStream in Java 8, deals with primitive ints. It helps to solve the old problems like finding maximum value in array, finding minimum value in array, sum of all elements in array, and average of all values in array in a new way. IntStream average() returns an OptionalDouble describing the arithmetic mean of elements of this strea
2 min read
IntStream max() in Java with examples
java.util.stream.IntStream in Java 8, deals with primitive ints. It helps to solve the problems like finding maximum value in array, finding minimum value in array, sum of all elements in array, and average of all values in array in a new way. IntStream max() returns an OptionalInt describing the maximum element of this stream, or an empty optional
2 min read
Practice Tags :