LongStream builder() returns a builder for an LongStream.
Syntax :
static LongStream.Builder builder()
Parameters :
- 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 :
// 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); } } |
Output :
0
Example 2 :
// 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); } } |
Output :
1 3 5 7 9