IntStream builder() method in Java


The builder() method in IntStream class is used to return a builder for an IntStream.

The syntax is as follows:

static IntStream.Builder builder()

Here, we have created an IntStream and used the builder() method. An element is added using add() method:

IntStream intStream = IntStream.builder().add(25).build();

The following is an example to implement IntStream builder() method in Java −

Example

 Live Demo

import java.util.*;
import java.util.stream.Stream;
import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.builder().add(25).build();
      intStream.forEach(System.out::println);
   }
}

output

25

Updated on: 30-Jul-2019

62 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements