Java Streams - LongStream.Builder build() example








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

Syntax

build has the following syntax.

LongStream build()

Example

The following example shows how to use build.

import java.util.stream.LongStream;
/*from   w  w w.  ja va 2  s .  c o m*/
public class Main {
  public static void main(String[] args) {
    LongStream.Builder b = LongStream.builder();
    b.accept(1L);
    b.accept(2L);
    b.accept(3L);
    b.accept(4L);
    
    b.build().forEach(System.out::println);
  }
}

The code above generates the following result.