Thursday, June 11, 2026
HomeLanguagesJavaDoubleStream boxed() in Java with Examples

DoubleStream boxed() in Java with Examples

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

Note : DoubleStream boxed() is a intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output.
Syntax :

Stream<Double> boxed()

Parameters :

  1. Stream : A sequence of elements supporting sequential and parallel aggregate operations.
  2. Double : The Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double.

Return Value : The function returns a Stream boxed to a Double.

Example 1 :




// Java code for DoubleStream boxed()
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.DoubleStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an DoubleStream
        DoubleStream stream = DoubleStream.of(3.2, 8.4, 3.6, 4.7);
  
        // Creating a Stream of Doubles
        // Using DoubleStream boxed() to return
        // a Stream consisting of the elements
        // of this stream, each boxed to a Double.
        Stream<Double> stream1 = stream.boxed();
  
        // Displaying the elements
        stream1.forEach(System.out::println);
    }
}


Output :

3.2
8.4
3.6
4.7

Example 2 :




// Java code for DoubleStream boxed()
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.DoubleStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an DoubleStream
        DoubleStream stream = DoubleStream.of(3.2, 8.4, 3.6, 4.7);
  
        // Creating a Stream of Doubles
        // Using DoubleStream boxed() to return
        // a Stream consisting of the elements
        // of this stream, each boxed to a Double.
        Stream<Double> stream1 = stream.boxed();
  
        Stream<Object> stream2 = Stream.concat(stream1,
                                   Stream.of("Geeks", "for", "Geeks"));
  
        // Displaying the elements
        stream2.forEach(System.out::println);
    }
}


Output :

3.2
8.4
3.6
4.7
Geeks
for
Geeks
RELATED ARTICLES

4 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS