DoubleStream boxed() method in Java

Java 8ProgrammingObject Oriented Programming

The boxed() method of the DoubleStream class returns a Stream consisting of the elements of this stream, boxed to Double.

The syntax is as follows

Stream<Double> boxed()

Here, Double is the class that wraps a value of the primitive type double in an object. To work with DoubleStream class in Java, import the following page

import java.util.stream.DoubleStream;

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

Example

 Live Demo

import java.util.*;
import java.util.stream.Stream;
import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(80.2, 84.6, 88.9, 92.9);
      Stream<Double> s = doubleStream.boxed();
      s.forEach(System.out::println);
   }
}

Output

80.2
84.6
88.9
92.9
raja
Published on 26-Mar-2019 14:52:55
Advertisements