Syntax error DoubleStream empty() method in Java

DoubleStream empty() method in Java



The empty() method of the DoubleStream class in Java returns an empty sequential DoubleStream.

The syntax is as follows:

static DoubleStream empty()

To use the DoubleStream class in Java, import the following package:

import java.util.stream.DoubleStream;

Let us create an empty DoubleStream:

DoubleStream doubleStream = DoubleStream.empty();

Now, let us check the number of elements in the stream. It will be 0, since the stream is set to empty:

doubleStream.count()

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

Example

 Live Demo

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

Here is the output. The result is 0 since the stream is set to empty:

Number of elements in the stream = 0
Updated on: 2019-07-30T22:30:25+05:30

73 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements