Java Streams - DoubleStream builder() example








DoubleStream builder() returns a builder for a DoubleStream.

Syntax

builder has the following syntax.

static DoubleStream.Builder builder()

Example

The following example shows how to use builder.

import java.util.stream.DoubleStream;
/*ww w .j  a  v  a2  s.com*/
public class Main {
  public static void main(String[] args) {
    DoubleStream.Builder b = DoubleStream.builder();
    b.accept(1.2);
    b.accept(1.2);
    b.accept(1.2);
    DoubleStream d = b.build();
    d.forEach(System.out::println);
  }
}

The code above generates the following result.