VOOZH about

URL: https://www.geeksforgeeks.org/java/array-stream-java/

⇱ Array to Stream in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Array to Stream in Java

Last Updated : 11 Jul, 2025
Prerequisite : Stream In Java

Using Arrays.stream() :

Syntax :
public static <T> Stream<T> getStream(T[] arr)
{
 return Arrays.stream(arr);
}

where, T represents generic type.
Example 1 : Arrays.stream() to convert string array to stream.
Output:
Geeks for Geeks 
Example 2 : Arrays.stream() to convert int array to stream.
Output:
1 2 3 4 5 
Example 3 : Arrays.stream() to convert long and double arrays to stream. Output:
Output:
3 5 6 8 9 
1.0 2.0 3.0 4.0 5.0 

Using Stream.of(), IntStream.of(), LongStream.of() & DoubleStream.of() :

Syntax :
public static <T> Stream<T> getStream(T[] arr)
{
 return Stream.of(arr);
}

where, T represents generic type.

Syntax of other functions is similar
Note : For object arrays, Stream.of() internally uses Arrays.stream(). Example 1 : Arrays.stream() to convert string array to stream.
Output:
Geeks for Geeks 
Example 2 : Arrays.stream() to convert int array to stream.
Output:
1 2 3 4 5 
Example 3 : Arrays.stream() to convert long and double arrays to stream.
Output:
Output:
3 5 6 8 9 
1.0 2.0 3.0 4.0 5.0 
Comment