byte[] a = {1,2,3};
System.out.println(Stream.of(a).count());
Byte[] b = {1,2,3};
System.out.println(Stream.of(b).count());
the re
For primitive arrays you should be using primitive streams, but unfortunately there is no ByteStream
. If you change your byte[]
to int[]
, you could write :
int[] a = {1,2,3};
System.out.println(IntStream.of(a).count());
Otherwise you get a Stream
whose single element is the input array, since both static
and static
expect a reference type as the Stream
element, so when you pass a primitive array, the only available reference type is the array itself.
In your System.out.println(Stream.of(b).count());
case, b
is an array of reference types, so static
is used to produce a Stream
of 3 elements.