IntStream.Builder build() method in Java


The build() method builds the stream. It transitions the builder to the built state. It returns the built stream. First, add elements to the stream

IntStream.Builder builder = IntStream.builder();
builder.add(10);
builder.add(25);
builder.add(33);

Now the stream is in the built phase

builder.build().forEach(System.out::println);

The syntax is as follows

IntStream build()

The following is an example to implement IntStream.Builder build() 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: 30-Jul-2019

66 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements