Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java array with empty second brackets

Tags:

java

In Java you can do this

int[][] i = new int[10][];

Does this just create 10 empty arrays of int? Does it have other implications?

like image 667
rubixibuc Avatar asked Apr 28 '26 00:04

rubixibuc


1 Answers

It creates a 10-entry array of int[]. Each of those 10 array references will initially be null. You'd then need to create them (and because Java doesn't have true multidimensional arrays, each of those 10 int[] entries can be of any length).

So for instance:

int i[][] = new int [10][];
i[0] = new int[42];
i[1] = new int[17];
// ...and so on
like image 119
T.J. Crowder Avatar answered Apr 30 '26 13:04

T.J. Crowder