Java Arrays - stream() Method
The java.util.Arrays.stream() method returns a sequential IntStream with the specified array as its source.
Syntax
public static IntStream stream(int[] array)
Parameters
array |
Specify the array, assumed to be unmodified during use. |
Return Value
Returns a IntStream for the array.
Exception
NA.
Example:
In the example below, the java.util.Arrays.stream() method returns a sequential IntStream with the given array as its source.
import java.util.*; import java.util.stream.*; public class MyClass { public static void main(String[] args) { //creating a int array int Arr[] = {1, 2, 3, 4, 5}; //creating IntStream object by converting //the array into stream IntStream stream = Arrays.stream(Arr); //printing the stream System.out.print("The stream contains: "); stream.forEach(str -> System.out.print(str + " ")); } }
The output of the above code will be:
The stream contains: 1 2 3 4 5
❮ Java.util - Arrays