IntStream empty() method in Java


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

Updated on: 30-Jul-2019

94 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements