Syntax error IntStream.Builder add() method in Java

IntStream.Builder add() method in Java



To insert element into the stream, you need to use the add() method of the IntStream.Builder.

The syntax is as follows:

default IntStream.Builder add(int t)

Here, parameter t is the element to be inserted.

Declare IntStream.Builder:

IntStream.Builder builder = IntStream.builder();

Add some elements to the Builder using add() method:

builder.add(10);
builder.add(25);
builder.add(33);
builder.add(42);

The following is an example to implement IntStream.Builder add() 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 in the stream...");
      builder.add(10);
      builder.add(25);
      builder.add(33);
      builder.add(42);
      builder.add(55);
      builder.add(68);
      builder.add(75);
      builder.build().forEach(System.out::println);
   }
}

output

Elements in the stream...
10
25
33
42
55
68
75
Updated on: 2019-07-30T22:30:25+05:30

150 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements