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








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

Syntax

accept has the following syntax.

void accept(int t)

Example

The following example shows how to use accept.

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

The code above generates the following result.