java - No method to get stream of byte array -
this question has answer here:
i want stream of byte array came know arrays
not have method stream of byte array.
byte[] bytearr = new byte[100]; arrays.stream(bytearr);//compile time error
my questions,
- why feature not supported ?
- how can stream of byte array ?
note : know can use byte[]
instead of byte[]
not answer question.
there 3 types of primitive streams: intstream, longstream , doublestream.
so, closest can have intstream, each byte in array promoted int.
afaik, simplest way build 1 byte array is
intstream.builder builder = intstream.builder(); (byte b : bytearray) { builder.accept(b); } intstream stream = builder.build();
edit: assylias suggests another, shorter way:
intstream stream = intstream.range(0, bytearr.length) .map(i -> bytearray[i]);
Comments
Post a Comment