Java Streams - LongStream.Builder accept(long t) example








LongStream.Builder accept(long t) adds an element to the stream being built.

Syntax

accept has the following syntax.

void accept(long t)

Example

The following example shows how to use accept.

import java.util.stream.LongStream;
/*  w w  w .  j  av a 2s  .  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.