Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

    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 result is 1 and 3, why?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
616 views
Welcome To Ask or Share your Answers For Others

1 Answer

Stream.of only accepts Objects as its arguments. A byte isn't an Object, but a byte array is. If a is an array of byte, then Stream.of(a) can only mean "stream of this one object, which is an array".

If you have a Byte[] array, then each element of the array is an object, so the compiler can guess that's what you mean.

There is information here about how you can stream a byte array: In Java 8, is there a ByteStream class?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...