Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

IntStream builder() in Java

  • Last Updated : 06 Dec, 2018

IntStream builder() returns a builder for an IntStream.

Syntax :

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. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

static IntStream.Builder builder()

Parameters :

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



Example 1 :




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

Output :

-1

Example 2 :




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

Output :

-1
0
2
4
7



My Personal Notes arrow_drop_up
Recommended Articles
Page :