IntStream.Builder add() method in Java Last Updated : 06 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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. Exceptions: This method throws IllegalStateException: when the builder has already transitioned to the built state. It means that the stream has entered the built phase and now no it can't be changed. Hence no more elements can be added into the stream. Below are the examples to illustrate add() method: Example 1: Java // Java code to show the implementation // of IntStream.Builder add(int t) import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // Declaring an empty Stream IntStream.Builder b = IntStream.builder(); // Inserting elements into the stream // using IntStream.Builder add(int t) b.add(4); b.add(5); b.add(6); b.add(7); // Creating the Stream // The stream has now entered the built phase // printing the elements System.out.println("Stream successfully built"); b.build().forEach(System.out::println); } } Output: Stream successfully built 4 5 6 7 Example 2: To illustrate IllegalStateException Java // Java code to show the implementation // of IntStream.Builder add(T t) import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // Declaring an empty Stream IntStream.Builder b = IntStream.builder(); // using IntStream.Builder add(T t) b.add(4); b.add(5); b.add(6); b.add(7); // Creating the Stream // The stream has now entered the built phase // printing the elements System.out.println("Stream successfully built"); b.build().forEach(System.out::println); // Trying to add another element into the stream // Since the Stream is in built phase // This operation is not possible now // Hence add() will throw exception now try { b.add(50); } catch (Exception e) { System.out.println("Exception thrown " + "when now adding element into the stream: " + e); } } } Output: Stream successfully built 4 5 6 7 Exception thrown when now adding element into the stream: java.lang.IllegalStateException Comment More infoAdvertise with us Next Article IntStream.Builder add() method in Java S Sahil_Bansall Follow Improve Article Tags : Misc Java Java - util package Java-Functions java-stream java-intstream Java-IntStream-Builder +3 More Practice Tags : JavaMisc Similar Reads IntStream.Builder accept() method in Java IntStream.Builder accept(int t) is used to insert an element into the element in the building phase of stream. It accepts an element to the stream being built. Syntax: void accept(int t) Parameters: This method accepts a mandatory parameter t which is the element to input into the stream. Exceptions 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 Stream.Builder add() method in Java Stream.Builder add(T 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 Stream.Builder<T> add(T t) Parameters: This method adds a mandatory parameter t which is the element to input into the stream. Ex 2 min read IntStream.Builder build() in Java with Examples 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 transition 2 min read DoubleStream.Builder accept() method in Java DoubleStream.Builder accept(double t) is used to insert an element into the element in the building phase of stream. It accepts an element to the stream being built. Syntax: void accept(double t) Parameters: This method accepts a mandatory parameter t which is the element to input into the stream. E 2 min read LongStream.Builder accept() method in Java LongStream.Builder accept(long t) is used to insert an element into the element in the building phase of stream. It accepts an element to the stream being built. Syntax: void accept(long t) Parameters: This method accepts a mandatory parameter t which is the element to input into the stream. Excepti 2 min read Deque add() method in Java The add(E e) method of Deque Interface inserts the element passed in the parameter to the end of the Deque if there is space. If the Deque is capacity restricted and no space is left for insertion, it returns an IllegalStateException. The function returns true on successful insertion. Syntax:Â Â bool 4 min read Stream.Builder accept() method in Java Stream.Builder accept(T 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: void accept(T t) Parameters: This method accepts a mandatory parameter t which is the element to input into the stream. Exceptions: This met 2 min read LongStream.Builder add(long t) in Java LongStream.Builder add(long 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 LongStream.Builder add(long t) Parameters: This method accepts a mandatory parameter t which is the element to input into the st 2 min read ArrayDeque add() Method in Java The Java.util.ArrayDeque.add(Object element) method in Java is used to add a specific element at the end of the Deque. The function is similar to the addLast() method of ArrayDeque in Java. Syntax: Array_Deque.add(Object element) Parameters: The parameter element is of the type ArrayDeque and refers 2 min read Like