LongStream.Builder accept() method in Java

Java 8Object Oriented ProgrammingProgramming

The accept() method of the LongStream.Builder class adds an element to the stream being built.

The syntax is as follows

void accept(long i)

Here, i is the input.

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

import java.util.stream.LongStream;

Create a LongStream

LongStream.Builder builder = LongStream.builder();

Add some elements

builder.accept(200L);
builder.accept(600L);
builder.accept(400L);

The following is an example to implement LongStream.Builder accept() 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(200L);
      builder.accept(600L);
      builder.accept(400L);
      builder.accept(350L);
      builder.accept(900L);
      builder.accept(850L);
      builder.accept(1200L);
      builder.accept(1500L);
      builder.build().forEach(System.out::println);
   }
}

Output

200
600
400
350
900
850
1200
1500
raja
Updated on 30-Jul-2019 22:30:25

Advertisements