Reputation: 1513
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];
Upvotes: 12
Views: 46255
Reputation: 272467
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];
Upvotes: 16
Reputation: 4454
may be you need a 2-d array
private byte[][] data = new byte[10][number];
that declares 10 byte arrays each of size number
Upvotes: 3