In this question it has already been answered that both expressions are equal, but in this case they produce different results. For a given int[] scores
, why does this work:
Arrays.stream(scores)
.forEach(System.out::println);
...but this does not:
Arrays.asList(scores).stream()
.forEach(System.out::println);
As far as I know .stream()
can be called on any Collection, which Lists definitely are. The second code snippet just returns a stream containing the array as a whole instead of the elements.