DoubleStream builder() in Java with Examples

DoubleStream builder() returns a builder for a DoubleStream.

Syntax :

static DoubleStream.Builder builder()

Parameters :



  1. DoubleStream.Builder : A mutable builder for a DoubleStream. A stream builder has a lifecycle, which starts in a building phase, during which elements can be added, and then transitions to a built phase, after which elements may not be added.

Return Value : The function returns a builder for a DoubleStream.

Example 1 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code for DoubleStream builder()
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 using
        // DoubleStream builder()
        DoubleStream stream = DoubleStream.builder()
                                  .add(2.3)
                                  .build();
  
        // Displaying the elements
        stream.forEach(System.out::println);
    }
}

chevron_right


Output :

2.3

Example 2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code for DoubleStream builder()
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 using
        // DoubleStream builder()
        DoubleStream stream = DoubleStream.builder().
        add(2.3).add(-1.2).add(3.5).add(10.74).build();
  
        // Displaying the elements
        stream.forEach(System.out::println);
    }
}

chevron_right


Output :

2.3
-1.2
3.5
10.74


My Personal Notes arrow_drop_up

In love with a semicolon because sometimes i miss it so badly)

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.