IntStream builder() method in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 28-Mar-2019 15:55:04
Advertisements