IntStream of() method in Java


The IntStream class in Java the following two forms of of() method

IntStream of(int t) method

The following of() method returns a sequential IntStream containing a single element. Here is the syntax

static IntStream of(int t)

Here, parameter t is the single element.

IntStream of(int… values) method

The following of() method returns a sequentially ordered stream whose elements are the specified values

static IntStream of(int… values)

Here, the parameter values are the elements of the new stream.

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

Example

 Live Demo

import java.util.*;
import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.of(10, 20, 30, 40, 50);
      intStream.forEach(System.out::println);
   }
}

Output

10
20
30
40
50

Updated on: 30-Jul-2019

364 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements