我正在尝试将字节数组转换为LinkedList<Byte>
:
//data is of type byte[]
List<Byte> list = Arrays.stream(toObjects(data)).boxed().collect(Collectors.toList());
Byte[] toObjects(byte[] bytesPrim) {
Byte[] bytes = new Byte[bytesPrim.length];
Arrays.setAll(bytes, n -> bytesPrim[n]);
return bytes;
}
第一行引发一条错误消息,指出:
对于类型
boxed()
,未定义方法Stream<Byte>
。知道为什么我会收到此错误消息以及如何规避此问题吗?
最佳答案
方法boxed()
仅设计用于某些基本类型(IntStream
,DoubleStream
和LongStream
)的流,以将流的每个原始值放入相应的包装类(Integer
,Double
,和Long
分别)。
表达式Arrays.stream(toObjects(data))
返回一个Stream<Byte>
,该ByteStream
自there is no such thing as a class起就已装箱。