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 code for Stream builder() import java.util.*; import java.util.stream.Stream; class GFG { // Driver code public static void main(String[] args) { // Using Stream builder() Stream.Builder<String> builder = Stream.builder(); // Adding elements in the stream of Strings Stream<String> stream = builder.add("Geeks").build(); // Displaying the elements in the stream stream.forEach(System.out::println); } } |
chevron_right
filter_none
Output :
Geeks
Example 2 :
// Java code for Stream builder() import java.util.*; import java.util.stream.Stream; class GFG { // Driver code public static void main(String[] args) { // Using Stream builder() Stream.Builder<String> builder = Stream.builder(); // Adding elements in the stream of Strings Stream<String> stream = builder.add("Geeks") .add("for") .add("Geeks") .add("GeeksQuiz") .build(); // Displaying the elements in the stream stream.forEach(System.out::println); } } |
chevron_right
filter_none
Output :
Geeks for Geeks GeeksQuiz
Example 3 :
// Java code for Stream builder() import java.util.*; import java.util.stream.Stream; import java.util.stream.Collectors; class GFG { // Driver code public static void main(String[] args) { // Using Stream builder() Stream.Builder<String> builder = Stream.builder(); // Adding elements in the stream of Strings Stream<String> stream = builder.add("GEEKS") .add("for") .add("Geeks") .add("GeEKSQuiz") .build(); // Converting elements to Lower Case // and storing them in List list List<String> list = stream.map(String::toLowerCase) .collect(Collectors.toList()); // Displaying the elements in list System.out.println(list); } } |
chevron_right
filter_none
Output :
[geeks, for, geeks, geeksquiz]
Recommended Posts:
- Stream.Builder add() method in Java
- Stream.Builder build() in Java
- Stream.Builder accept() method in Java
- DoubleStream builder() in Java with Examples
- DoubleStream.Builder add(double t) in Java with Examples
- IntStream.Builder build() in Java with Examples
- Locale.Builder build() method in Java with Examples
- Locale.Builder setScript() method in Java with Examples
- Locale.Builder setVariant() method in Java with Examples
- Locale.Builder setRegion() method in Java with Examples
- Locale.Builder setLanguage() method in Java with Examples
- Locale.Builder setLanguageTag() method in Java with Examples
- Locale.Builder setUnicodeLocaleKeyword() method in Java with Examples
- Locale.Builder clearExtensions() method in Java with Examples
- Locale.Builder setExtension() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



