Stream builder() devuelve un constructor para un Stream.
Sintaxis:
static <T> Stream.Builder<T> builder() where, T is the type of elements.
Valor de retorno: un generador de secuencias.
Ejemplo 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); } }
Producción :
Geeks
Ejemplo 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); } }
Producción :
Geeks for Geeks GeeksQuiz
Ejemplo 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); } }
Producción :
[geeks, for, geeks, geeksquiz]
Publicación traducida automáticamente
Artículo escrito por Sahil_Bansall y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA