Monday, January 26, 2026
HomeLanguagesJavaIntStream asDoubleStream() in Java

IntStream asDoubleStream() in Java

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 :




// Java code for DoubleStream asDoubleStream()
// to return a DoubleStream consisting of
// the elements of this stream
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.DoubleStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an IntStream
        IntStream stream = IntStream.of(3, 5, 9, 12, 14);
  
        // Using DoubleStream asDoubleStream()
        DoubleStream stream1 = stream.asDoubleStream();
  
        // Displaying DoubleStream consisting of
        // the elements of this stream
        stream1.forEach(System.out::println);
    }
}


Output :

3.0
5.0
9.0
12.0
14.0

Example 2 :




// Java code for DoubleStream asDoubleStream()
// to return a DoubleStream consisting of
// the elements of this stream
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.DoubleStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an IntStream and using asDoubleStream()
        DoubleStream stream = IntStream.range(3, 8).asDoubleStream();
  
        // Displaying DoubleStream consisting of
        // the elements of this stream
        stream.forEach(System.out::println);
    }
}


Output :

3.0
4.0
5.0
6.0
7.0

Example 3 :




// Java code for DoubleStream asDoubleStream()
// to return a DoubleStream consisting of
// the elements of this stream
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.DoubleStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an IntStream and using asDoubleStream()
        // to display the elements of IntStream and
        // DoubleStream together
        DoubleStream stream = IntStream.range(3, 8)
                                  .peek(System.out::println)
                                  .asDoubleStream();
  
        // Displaying DoubleStream consisting of
        // the elements of this stream
        stream.forEach(System.out::println);
    }
}


Output :

3
3.0
4
4.0
5
5.0
6
6.0
7
7.0
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7221 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS