IntStream asDoubleStream() in Java
Last Updated :
06 Dec, 2018
IntStream asDoubleStream() returns a DoubleStream consisting of the elements of this stream, converted to double. This is an intermediate operation. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output.
Syntax :
DoubleStream asDoubleStream()
Where, DoubleStream is a sequence of
primitive double-valued element.
Return Value : IntStream asDoubleStream() returns a
DoubleStream consisting of the elements of this stream,
converted to double.
Example 1 :
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.DoubleStream;
class GFG {
public static void main(String[] args)
{
IntStream stream = IntStream.of( 3 , 5 , 9 , 12 , 14 );
DoubleStream stream1 = stream.asDoubleStream();
stream1.forEach(System.out::println);
}
}
|
Output :
3.0
5.0
9.0
12.0
14.0
Example 2 :
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.DoubleStream;
class GFG {
public static void main(String[] args)
{
DoubleStream stream = IntStream.range( 3 , 8 ).asDoubleStream();
stream.forEach(System.out::println);
}
}
|
Output :
3.0
4.0
5.0
6.0
7.0
Example 3 :
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.DoubleStream;
class GFG {
public static void main(String[] args)
{
DoubleStream stream = IntStream.range( 3 , 8 )
.peek(System.out::println)
.asDoubleStream();
stream.forEach(System.out::println);
}
}
|
Output :
3
3.0
4
4.0
5
5.0
6
6.0
7
7.0
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...