LongStream builder() example

Description

LongStream builder() returns a builder for a LongStream.

Syntax

builder has the following syntax.


static LongStream.Builder builder()

Example

The following example shows how to use builder.


import java.util.stream.LongStream;
/*w w  w  . j av a 2  s  .co m*/
public class Main {
  public static void main(String[] args) {
    LongStream.Builder b = LongStream.builder();
    b.accept(2L);
    b.accept(2L);
    b.accept(2L);
    
    LongStream s = b.build();
    s.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