IntStream asDoubleStream() method in Java

Java 8ProgrammingObject Oriented Programming

The asDoubleStream() method in the IntStream class returns a DoubleStream consisting of the elements of this stream, converted to double.

The syntax is as follows

DoubleStream asDoubleStream()

First, create an IntStream

IntStream intStream = IntStream.of(20, 30, 40, 50, 60, 70, 80);

After that, convert it to double with asDoubleStream() method

DoubleStream doubleStream = intStream.asDoubleStream();

The following is an example to implement IntStream asDoubleStream() method in Java

Example

 Live Demo

import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.of(20, 30, 40, 50, 60, 70, 80);
      DoubleStream doubleStream = intStream.asDoubleStream();
      doubleStream.forEach(System.out::println);
   }
}

Output

20.0
30.0
40.0
50.0
60.0
70.0
80.0
raja
Published on 26-Mar-2019 12:35:43
Advertisements