IntStream builder() in Java
IntStream builder() returns a builder for an IntStream.
Syntax :
static IntStream.Builder builder()
Parameters :
- 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 :
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.IntStream;
class GFG {
public static void main(String[] args)
{
IntStream stream = IntStream.builder().add(- 1 ).build();
stream.forEach(System.out::println);
}
}
|
Output :
-1
Example 2 :
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.IntStream;
class GFG {
public static void main(String[] args)
{
IntStream stream = IntStream.builder()
.add(- 1 ).add( 0 ).add( 2 ).add( 4 ).add( 7 ).build();
stream.forEach(System.out::println);
}
}
|
Output :
-1
0
2
4
7
Last Updated :
06 Dec, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...