Question:
How to convert byte[] to Byte[] in java?
Code:
import java.util.Arrays; public class BytesToBytes { public static void main(String[] args) { byte[] b = new byte[]{1,2,3,4,5,6,7,8,9}; Byte[] B = new Byte[b.length]; for (int i = 0; i < b.length; i++) { B[i] = Byte.valueOf(b[i]); } System.out.println("byte[] b: " + Arrays.toString(b)); System.out.println("Byte[] B: " + Arrays.toString(B)); } }
Output:
$ java BytesToBytes byte[] b: [1, 2, 3, 4, 5, 6, 7, 8, 9] Byte[] B: [1, 2, 3, 4, 5, 6, 7, 8, 9]