Stream.Builder build() example

Description

Stream.Builder build() builds the stream, transitioning this builder to the built state.

Syntax

build has the following syntax.


Stream<T> build()

Example

The following example shows how to use build.


import java.util.stream.Stream;
/*w w w . j a v a 2s  .co  m*/
public class Main {
  public static void main(String[] args) {
    Stream.Builder<String> b = Stream.builder();
    b.accept("a");
    b.accept("b");
    b.accept("c");
    b.accept("d");
    b.accept("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