How to use asDoubleStream in IntStream?

Here is an example to explain how to use asDoubleStream() in IntStream.

Syntax:

Modifier and Type         Method
DoubleStream              asDoubleStream()
package com.nourit.java8.Streams.IntStream;

import java.util.stream.DoubleStream;
import java.util.stream.IntStream;

public class IntStreamAsDoubleStream {

	public static void main(String[] args) {
		System.out.println("---------- First Example -----------------");
		IntStream i = IntStream.of(0, 1, 2, 3, 4, 5, 6);
		//Returns a DoubleStream consisting of the elements of this stream, converted to double.
		DoubleStream doubleStream1 = i.asDoubleStream();	
		 
		doubleStream1.forEach(System.out::println);
		System.out.println("---------- Seconed Example -----------------");
		DoubleStream doubleStream2 = IntStream.range(0, 7).mapToDouble(n -> n);
		doubleStream2.forEach(System.out::println);
		System.out.println("---------------------------------------");
	}
}

Output:

---------- First Example -----------------
0.0
1.0
2.0
3.0
4.0
5.0
6.0
---------- Seconed Example -----------------
0.0
1.0
2.0
3.0
4.0
5.0
6.0
---------------------------------------

 

NOUR-IT

IT Training Center for Java and Web technology. If you enjoy and like our tutorials and believe in our mission, Please Subscribe us on Youtube and follow us on Twitter, or befriend us on Facebook or Google Plus.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*