Stream.Builder build() builds the stream, transitioning this builder to the built state.
Syntax :
Java
Output :
Java
Stream<T> build()Exceptions :
- IllegalStateException : If the builder has already transitioned to the built state, IllegalStateException is thrown. It signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.
// Java code to show the implementation
// of Stream.Builder build()
import java.util.stream.Stream;
class GFG {
// Driver code
public static void main(String[] args)
{
Stream.Builder<String> str_b = Stream.builder();
str_b.add("Geeks");
str_b.add("for");
str_b.add("GeeksforGeeks");
str_b.add("Data Structures");
str_b.add("Geeks Classes");
// creating the string stream
Stream<String> s = str_b.build();
// printing the elements
s.forEach(System.out::println);
}
}
Geeks for GeeksforGeeks Data Structures Geeks ClassesExample 1 :
// Java code to show the implementation
// of Stream.Builder build()
import java.util.stream.Stream;
class GFG {
// Driver code
public static void main(String[] args)
{
Stream.Builder<String> str_b = Stream.builder();
str_b.add("Geeks");
str_b.add("for");
str_b.add("GeeksforGeeks");
str_b.add("Data Structures");
str_b.add("Geeks Classes");
// creating the string stream
Stream<String> s = str_b.build();
// printing the elements
s.forEach(System.out::println);
}
}
Output :
Geeks for GeeksforGeeks Data Structures Geeks Classes