DoubleStream builder() returns a builder for a DoubleStream.
Syntax :
static DoubleStream.Builder builder()
Parameters :
- 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