Open In App
Related Articles

LongStream builder() in Java

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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 :
// 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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!


Last Updated : 06 Dec, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads