Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring an Array of Byte Arrays in Java

How can I declare an array of byte arrays with a limited size for the array? This is what I was thinking but it's not working and I couldn't find anything.

private Integer number =10000;
private byte[] data[];
data = new byte[][number];
like image 1000
gtdevel Avatar asked Jan 01 '12 21:01

gtdevel


2 Answers

Something like this?

private byte[][] data;  // This is idiomatic Java

data = new byte[number][];

This creates an array of arrays. However, none of those sub-arrays yet exist. You can create them thus:

data[0] = new byte[some_other_number];
data[1] = new byte[yet_another_number];
...

(or in a loop, obviously).

Alternatively, if they're all the same length, you can do the whole thing in one hit:

data = new byte[number][some_other_number];
like image 92
Oliver Charlesworth Avatar answered Sep 24 '22 19:09

Oliver Charlesworth


may be you need a 2-d array

private byte[][] data = new byte[10][number];

that declares 10 byte arrays each of size number

like image 44
Adithya Surampudi Avatar answered Sep 23 '22 19:09

Adithya Surampudi