The build() method in Java LongStream.Builder


The build() method of the LongStream.Builder class builds the stream and returns the built stream. The following is the syntax:

LongStream build()

Import the following package for the LongStream.Builder class in Java:

import java.util.stream.LongStream;

Declare a LongStream.Builder and add elements:

LongStream.Builder builder = LongStream.builder();

builder.add(24000L);
builder.add(47470L);
builder.add(12999L);

Now, use the build() method to build the stream:

builder.build()

The following is an example displaying how to implement build() method of LongStream.Builder 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.add(24000L);
      builder.add(47470L);
      builder.add(12999L);
      builder.add(55757L);
      builder.add(12999L);
      builder.add(55757L);
      builder.build().forEach(System.out::println);
   }
}

output

24000
47470
12999
55757
12999
55757

Updated on: 30-Jul-2019

106 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements