What is the IntStream.Builder accept() method in Java


Insert an element into IntStream using the IntStream.Builder accept() method. It adds element to the stream being built.

The syntax is as follows:

void accept(int t)

Here, parameter t is the input argument.

The elements are inserted as shown below in the stream:

builder.accept(10);
builder.accept(15);
builder.accept(25);
builder.accept(39);
builder.accept(45);

The following is an example to implement IntStream.Builder accept() method in Java:

Example

 Live Demo

import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream.Builder builder = IntStream.builder();
      System.out.println("Elements of the stream...");
      builder.accept(10);
      builder.accept(15);
      builder.accept(25);
      builder.accept(39);
      builder.accept(45);
      builder.accept(55);
      builder.accept(80);
      builder.build().forEach(System.out::println);
   }
}

output

Elements of the stream...
10
15
25
39
45
55
80

Updated on: 30-Jul-2019

71 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements