IntStream skip() method in Java


The skip() method of the IntStream class in Java returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream.

The syntax is as follows

IntStream skip(long n)

Here, n is the number of elements to skip. The method returns the new stream.

Create an IntStream and add some elements within a range using range() method

IntStream intStream = IntStream.range(20, 40);

Now to skip some elements and only display the rest of them, use the skip() method

intStream.skip(15)

The following is an example to implement IntStream skip() method in Java. It skips 15 elements since we have set the parameter value of the skip() method as 15

Example

 Live Demo

import java.util.*;
import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.range(20, 40);
      intStream.skip(15).forEach(System.out::println);
   }
}

Output

35
36
37
38
39

Updated on: 30-Jul-2019

191 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements