int*_*_32 16 java byte bytearray
有Vector和DataOutputStream.我需要将Vector中的字节(toArray返回Byte [])写入流,但它只能理解byte [].如何将Byte []转换为byte []?
byte[] toPrimitives(Byte[] oBytes)
{
byte[] bytes = new byte[oBytes.length];
for(int i = 0; i < oBytes.length; i++) {
bytes[i] = oBytes[i];
}
return bytes;
}
Run Code Online (Sandbox Code Playgroud)
逆:
// byte[] to Byte[]
Byte[] toObjects(byte[] bytesPrim) {
Byte[] bytes = new Byte[bytesPrim.length];
int i = 0;
for (byte b : bytesPrim) bytes[i++] = b; // Autoboxing
return bytes;
}
Run Code Online (Sandbox Code Playgroud)
freeone3000在这个答案中做出了贡献:)