DoubleStream count() method in Java


The count() method of the DoubleStream class returns the count of the elements in the stream.

The syntax is as follows:

long count()

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

import java.util.stream.DoubleStream;

Create DoubleStream and add some elements:

DoubleStream doubleStream = DoubleStream.of(50.8, 67.9, 35.7, 23.6, 89.9);

Now, get the count of elements in the DoubleStream:

long res = doubleStream.count();

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

Example

 Live Demo

import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(50.8, 67.9, 35.7, 23.6, 89.9);
      long res = doubleStream.count();
      System.out.println("Count of elements in the stream = "+res);
   }
}

Output

Count of elements in the stream = 5

Updated on: 30-Jul-2019

90 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements