LongStream builder() in Java

LongStream builder() returns a builder for an LongStream.

Syntax :

static LongStream.Builder builder()

Parameters :



  1. LongStream.Builder : A mutable builder for a LongStream. 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 an LongStream.

Example 1 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code for LongStream builder()
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.LongStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating a LongStream using
        // LongStream builder()
        LongStream stream = LongStream.builder().add(0).build();
  
        // Displaying the elements
        stream.forEach(System.out::println);
    }
}

chevron_right


Output :

0

Example 2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code for LongStream builder()
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.LongStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating a LongStream using
        // LongStream builder()
        LongStream stream = LongStream.builder().add(1L).add(3L).add(5L).add(7L).add(9L).build();
  
        // Displaying the elements
        stream.forEach(System.out::println);
    }
}

chevron_right


Output :

1
3
5
7
9


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.