Currently whenever I need to create stream from an array, I do
String[] array = {\"x1\", \"x2\"};
Arrays.asList(array).stream();
Is there s
You can use Arrays.stream :
Arrays.stream(array);
This ensures the return type of steam based on your array input type if its String []
then return Stream
, if int []
then returns IntStream
When you already know input type array then good to use specific one like for input type int[]
IntStream.of(array);
This returns Intstream.
In first example, Java uses method overloading
to find specific method based on input types while as in second you already know the input type and calling specific method.