How to Declare and Set a Byte Array

byte was added in API Level 1
The byte data type

1.Add the code below to the onCreate method. This will create an empty array of the data type byte named myByteArray, allocating memory for 1024 bytes.

byte[] myByteArray = new byte[1024];

2. Compile and run!

3. Another example, to create and initialize a byte array to the letters 'h e l l o'.

       byte[] myByteArray2 = {'h', 'e', 'l', 'l', 'o'};

Related Articles: