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

user926958 picture user926958 · Oct 18, 2012 · Viewed 89.8k times · Source

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?

Answer

LaCrampe picture LaCrampe · Sep 5, 2016

byte[] to Byte[] :

byte[] bytes = ...;
Byte[] byteObject = ArrayUtils.toObject(bytes);

Byte[] to byte[] :

Byte[] byteObject = new Byte[0];
byte[] bytes = ArrayUtils.toPrimitive(byteObject);