Java Streams - IntStream.Builder build() example








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

Syntax

build has the following syntax.

IntStream build()

Example

The following example shows how to use build.

import java.util.stream.IntStream;
/* w  ww .j a va2  s  .  com*/
public class Main {
  public static void main(String[] args) {
    IntStream.Builder b = IntStream.builder();
    b.add(1)
     .add(2)
     .add(3)
     .add(4);
    
    b.build().forEach(System.out::println);
  }
}

The code above generates the following result.