IntStream.Builder build() in Java with Examples Last Updated : 06 Dec, 2018 Comments Improve Suggest changes Like Article Like Report IntStream.Builder build() builds the stream, transitioning this builder to the built state. Syntax : IntStream build() Return Value: This method returns the built stream. Note: 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. The built phase begins when the build() method is called, which creates an ordered stream whose elements are the elements that were added to the stream builder, in the order they were added. Below are the examples to illustrate build() method: Example 1: Java // Java code to show the implementation // of IntStream.Builder build() import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // Creating a Stream in building phase IntStream.Builder b = IntStream.builder(); // Adding elements into the stream b.add(1); b.add(2); b.add(3); b.add(4); // Constructing the built stream using build() // This will enter the stream in built phase b.build().forEach(System.out::println); } } Output: 1 2 3 4 Example 2: Trying to add element in after calling build() method (when stream is in built phase). Java // Java code to show the implementation // of IntStream.Builder build() import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // Creating a Stream in building phase IntStream.Builder b = IntStream.builder(); // Adding elements into the stream b.add(1); b.add(2); b.add(3); b.add(4); // Constructing the built stream using build() // This will enter the stream in built phase // Now no more elements can be added to this stream b.build().forEach(System.out::println); // Trying to add more elements in built phase // This will cause exception try { b.add(50); } catch (Exception e) { System.out.println("\nException: " + e); } } } Output: 1 2 3 4 Exception: java.lang.IllegalStateException Comment More infoAdvertise with us Next Article IntStream.Builder build() in Java with Examples S Sahil_Bansall Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Stream builder() in Java with Examples Stream builder() returns a builder for a Stream. Syntax : static <T> Stream.Builder<T> builder() where, T is the type of elements. Return Value : A stream builder. Example 1 : Java // Java code for Stream builder() import java.util.*; import java.util.stream.Stream; class GFG { // Driver 2 min read DoubleStream builder() in Java with Examples DoubleStream builder() returns a builder for a DoubleStream. Syntax : static DoubleStream.Builder builder() Parameters : DoubleStream.Builder : A mutable builder for a DoubleStream. A stream builder has a lifecycle, which starts in a building phase, during which elements can be added, and then trans 1 min read IntStream.Builder add() method in Java IntStream.Builder add(int t) is used to insert an element into the element in the building phase of stream. It adds an element to the stream being built. Syntax: default IntStream.Builder add(int t) Parameters: This method accepts a mandatory parameter t which is the element to input into the stream 2 min read Locale.Builder build() method in Java with Examples The build() method of java.util.Locale.Builder class in Java is used to build a Locale from the values specified to this Locale.Builder instance. This method returns a Locale instance after building it. Syntax: public Locale build() Parameter: This method do not accept any parameter. Return Type: Th 2 min read 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 b 1 min read Like