Java Streams - DoubleStream.Builder build() example








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

Syntax

build has the following syntax.

DoubleStream build()

Example

The following example shows how to use build.

import java.util.stream.DoubleStream;
//  w ww . j  a v a 2  s.  c  om
public class Main {
  public static void main(String[] args) {
    DoubleStream.Builder b = DoubleStream.builder();
    b.accept(1.1);
    b.accept(2.2);
    b.accept(3.3);
    b.accept(4.4);
    
    b.build().forEach(System.out::println);
  }
}

The code above generates the following result.