0 votes
in JAVA by
Can you convert an array to Stream and how?

1 Answer

0 votes
by
Yes, you can convert an array to Stream in Java. The Stream class provides a factory method to create a Stream from an array, like Stream .of(T ...) which accepts a variable argument, that means you can also pass an array to it as shown in the following example:

String[] languages = {"Java", "Python", "JavaScript"};

Stream numbers = Stream.of(languages);

numbers.forEach(System.out::println);

Output:

Java

Python

JavaScript

So, yes, it's possible to convert an array to Stream in Java 8. You can even convert an ArrayList to Stream, as explained in that article.

Related questions

+1 vote
asked Apr 15, 2021 in JAVA by SakshiSharma
+1 vote
asked Apr 15, 2021 in JAVA by SakshiSharma
...