Related Articles

Related Articles

LongStream builder() in Java
  • Last Updated : 06 Dec, 2018

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

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.




My Personal Notes arrow_drop_up
Recommended Articles
Page :