LongStream skip() method in Java


The skip() method of the LongStream class 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 −

LongStream skip(long numEle)

Here, numEle is the number of elements to be skipped.

To use the LongStream class in Java, import the following package −

import java.util.stream.LongStream;

First, create a LongStrem and add some elements −

LongStream longStream = LongStream.range(5000L, 5025l);

Now, use the skip() method to skip the first n number of elements −

longStream.skip(15)

The following is an example to implement LongStream skip() method in Java −

Example

 Live Demo

import java.util.stream.LongStream;
public class Demo {
   public static void main(String[] args) {
      LongStream longStream = LongStream.range(5000L, 5025l);
      // skips the first 15 elements
      longStream.skip(15).forEach(System.out::println);
   }
}

Output

5015
5016
5017
5018
5019
5020
5021
5022
5023
5024

Updated on: 30-Jul-2019

91 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements