Java Streams - IntStream.Builder add(int t) example








IntStream.Builder add(int t) adds an element to the stream being built.

Syntax

add has the following syntax.

default IntStream.Builder add(int t)

Example

The following example shows how to use add.

import java.util.stream.IntStream;
// w ww  . ja v  a  2  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.