IntStream empty() method in Java

Java 8Object Oriented ProgrammingProgramming

The empty() method of the IntStream class returns an empty sequential IntStream.

The syntax is as follows

static IntStream empty()

This is how you can create an empty IntStream

IntStream intStream = IntStream.empty();

Now, using the count() method you can check the count of elements in the stream, which is 0 since we created an empty stream

IntStream intStream = IntStream.empty();

The following is an example to implement IntStream empty() method in Java

Example

 Live Demo

import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.empty();
      System.out.println("The number of elements in the stream = "+intStream.count());
   }
}

Output

The number of elements in the stream = 0
raja
Published on 28-Mar-2019 07:50:45
Advertisements