如何将byte []转换为Byte []及其他方法? [英] How to convert byte[] to Byte[] and the other way around?

查看:143
本文介绍了如何将byte []转换为Byte []及其他方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在不使用任何第三方库的情况下,如何将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类是基元byte包装器.这应该可以完成工作:

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 []转换为Byte []及其他方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆