VOOZH about

URL: https://www.geeksforgeeks.org/java/arrays-stream-method-in-java/

⇱ Arrays.stream() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Arrays.stream() Method in Java

Last Updated : 11 Jul, 2025

Arrays.stream() method is used to get a sequential Stream from the elements of an array passed as a parameter. Below is a simple example that uses Arrays.stream() to convert a String array into a Stream for sequential processing.

Example:


Output
Geeks for Geeks 

Syntax of Arrays.stream() Method

1. To Convert Entire Array

public static <T> Stream<T> stream(T[] array)

Parameters:

  • array: This is the array, whose elements are to be converted into a sequential stream. It is a mandatory parameter of type T[] (an array of any object type).

Return Type: This method returns a Stream<T>, which is a sequential stream of the elements of the provided array.

2. To Convert a Range within an Array

public static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusive)

Parameters:

  • array: The array to be partially converted to a stream.
  • startInclusive: The starting index of the range to include in the stream (inclusive).
  • endExclusive: The end index of the range (exclusive).

Return Type: This returns a Stream<T>, which is a sequential stream that contains elements from the specified range in the array.

Example 1: Convert an int Array to an IntStream

In this example, we create an IntStream from a full int array and print each element in sequence.


Output
1 2 3 4 

Example 2: Convert a Specific Range of a String Array to a Stream

In this example, we will generate a Stream from a specific range within a String array and then will print the elements within the selected range.


Output
for 

Example 3: Convert a Specific Range of an int Array to an IntStream

In this example, we will create an IntStream from a range of elements in an int array and then we will print only those elements within the specified range.


Output
2 3 
Comment
Article Tags: