Java Streams - Stream builder() example








Stream builder() returns a builder for a Stream.

Syntax

builder has the following syntax.

static <T> Stream.Builder<T> builder()

Example

The following example shows how to use builder.

import java.util.stream.Stream;
/*from  w  w w  .  j a  v  a  2 s  .  c  o  m*/
public class Main {
  public static void main(String[] args) {
    Stream.Builder<String> b = Stream.builder();
    b.accept("a");
    Stream<String> s = b.build();
    s.limit(10)
     .forEach(System.out::println); 

  }
}

The code above generates the following result.