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.
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:
Stream successfully built 4 5 6 7
Example 2: To illustrate IllegalStateException
Stream successfully built 4 5 6 7 Exception thrown when now adding element into the stream: java.lang.IllegalStateException
My Personal Notes arrow_drop_up
Please Login to comment...