Stream.Builder add(T t) example

Description

Stream.Builder add(T t) adds an element to the stream being built.

Syntax

add has the following syntax.


default Stream.Builder<T> add(T t)

Example

The following example shows how to use add.


import java.util.stream.Stream;
/* w ww .  j a  va  2 s. c  om*/
public class Main {
  public static void main(String[] args) {
    Stream.Builder<String> b = Stream.builder();
    b.add("a");
    b.add("b");
    b.add("c");
    b.add("d");
    b.add("e");
    
    Stream<String> s = b.build();
    s.forEach(System.out::println); 

  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder