LongStream.Builder add(long t) example

Description

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

Syntax

add has the following syntax.


default LongStream.Builder add(long t)

Example

The following example shows how to use add.


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

The code above generates the following result.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder