How to convert a Java 8 Stream to an Array?



This post shows the simplest way to convert Java 8 stream to an Array with an example snippet.

How to convert a Java 8 Stream to an Array?

Stream<String> stringStream = Stream.of("a", "b", "c");
String[] stringArray = stringStream.toArray(size -> new String[size]);
Arrays.stream(stringArray).forEach(System.out::println);
Prints:
a
b
c

Reference

https://stackoverflow.com/questions/23079003/how-to-convert-a-java-8-stream-to-an-array

Comments