如何将此字节数组转换为 double 组。
byte[] byteArray = {1,0,0,1,0};
我喜欢不使用循环来转换它,因为这个字节数组有大量元素。
请帮助我
最佳答案
可能的“无循环”解决方案将使用 System.arraycopy
或Arrays.copyOf
,但在这些解决方案中,您无法避免将 byte[]
转换为 double[]
。问题是根据specification,这种类型转换是不可能的。 :
Given a compile-time reference type S (source) and a compile-time reference type T (target), a casting conversion exists from S to T if no compile-time errors occur due to the following rules. [...] If S is an array type SC[], that is, an array of components of type SC: [...] - If T is an array type TC[], that is, an array of components of type TC, then a compile-time error occurs unless one of the following is true: - TC and SC are the same primitive type. - [...]
使用循环。另请参阅here .
关于java - 如何将字节数组转换为 double 组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18356906/