如何转换字节[]为byte [],和周围的其他方式? [英] how to convert byte[] to Byte[], and the other way around?
本文介绍了如何转换字节[]为byte [],和周围的其他方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何转换的byte []为byte [],也字节]为byte [],在不使用任何第三方库的情况下?有没有办法做到这一点快速仅仅使用标准库?
How to convert byte[] to Byte[], and also Byte[] to byte[], in the case of not using any 3rd party library? Is there a way to do it fast just using the standard library?
推荐答案
字节
类是一个的包装的为原始字节
。这应该做的工作:
Byte
class is a wrapper for the primitive byte
. This should do the work:
byte[] bytes = new byte[10];
Byte[] byteObjects = new Byte[bytes.length];
int i=0;
// Associating Byte array values with bytes. (byte[] to Byte[])
for(byte b: bytes)
byteObjects[i++] = b; // Autoboxing.
....
int j=0;
// Unboxing byte values. (Byte[] to byte[])
for(Byte b: byteObjects)
bytes[j++] = b.byteValue();
这篇关于如何转换字节[]为byte [],和周围的其他方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文