How to convert byte[] to Byte[] and the other way around?

前端 未结 7 708
小鲜肉
小鲜肉 2020-12-02 10:18

How to convert byte[] to Byte[] and also Byte[] to byte[], in the case of not using any 3rd party library?

Is the

7条回答
  •  没有蜡笔的小新
    2020-12-02 10:45

    From byte[] to Byte[]:

        byte[] b = new byte[]{1,2};
        Byte[] B = new Byte[b.length];
        for (int i = 0; i < b.length; i++)
        {
            B[i] = Byte.valueOf(b[i]);
        }
    

    From Byte[] to byte[] (using our previously-defined B):

        byte[] b2 = new byte[B.length];
        for (int i = 0; i < B.length; i++)
        {
            b2[i] = B[i];
        }
    

提交回复
热议问题