Convert Array to Stream in Java

In this Convert Array to Stream in Java post, we show you how to convert a array to stream using use Arrays.stream, Stream.of or List.stream method. Java 8 is so amazing. With lots of new features and Stream APIs Java 8 is one of the best release.

Let’s dig deeper via some examples:

1. Convert Object array to stream
We have the array of String as below:

And this array is convert to stream by three ways below.

a) Using Arrays.stream()

b) Using Stream.of()

c) Using List.stream()

Here is the demo program with three ways

Output
Convert Array to Stream in Java

2. Convert Primitive Array to Stream

We are considering the primitive array below:

And this primitive array is convert to stream by two ways below

a) Using Arrays.stream()

b) Using Stream.of()

Here is the demo program with two ways

Output

That’s all about Convert Array to Stream in Java.

References
Arrays JavaDoc
Stream JavaDoc

Download complete source code, click link below

Java8ArrayToStream.zip (2 downloads)

Leave a Comment

*

Please share it if you found this useful
Hide Buttons