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] = 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]