DoubleStream of() method in Java


The DoubleStream class in Java the following two forms of the of() method

The following of() method returns a sequential DoubleStream containing a single element. Here is the syntax

static DoubleStream of(double t)

Here, parameter t is the single element.

The following of() method returns a sequential ordered stream whose elements are the specified values

static DoubleStream of(double… values)

Here, the parameter values are the elements of the new stream.

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

import java.util.stream.DoubleStream;

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

Example

 Live Demo

import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(20.5, 35.9, 55.8, 68.7, 80.5);
      doubleStream.forEach(System.out::println);
   }
}

Output

20.5
35.9
55.8
68.7
80.5

Updated on: 30-Jul-2019

123 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements