Skip to content
Related Articles

Related Articles

DoubleStream builder() in Java with Examples
  • Last Updated : 03 Apr, 2018

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 :






// 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);
    }
}

Output :

2.3

Example 2 :




// 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);
    }
}

Output :

2.3
-1.2
3.5
10.74

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :