LongStream.Builder build() method in Java


The build() method of the LongStream.Builder class builds the stream, transitioning this builder to the built state.

The syntax is as follows

LongStream build()

To use the LongStream.Builder class in Java, import the following package

import java.util.stream.LongStream;

The following is an example to implement LongStream.Builder build() method in Java

Example

 Live Demo

import java.util.stream.LongStream;
public class Demo {
   public static void main(String[] args) {
      LongStream.Builder builder = LongStream.builder();
      builder.accept(255L);
      builder.accept(570L);
      builder.accept(355L);
      builder.accept(155L);
      builder.accept(955L);
      builder.accept(1800L);
      builder.accept(155L);
      builder.accept(2900L);
      builder.build().forEach(System.out::println);
   }
}

Output

255
570
355
155
955
1800
155
2900

Updated on: 30-Jul-2019

56 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements