i have a class called (User) and i want to make a multidimensional array of it i have wrote
static User [][] userlist=new User[6][];
and i have a compiler error that is : illegal start of expression
thanks a lot .
i have a class called (User) and i want to make a multidimensional array of it i have wrote
static User [][] userlist=new User[6][];
and i have a compiler error that is : illegal start of expression
thanks a lot .
On
Similar to @Mark solution, you can initialise a multi-dimensional array
private static int[][] matrix = {
{ 1,2,3,4,5 },
{ 6,7,8,9,10 }
};
On
There are a number of nice answers, so this is more informative than anything:
The problem is that all dimensions must be specified explicitly or implicitly -- and the new X[..][..][..] etc, (explicitly specified dimensions) form requires that each dimension (..) is a (non-negative) integer expression. The javac compiler is throwing that error because it found the last ] but was expecting an integer expression.
new User[6][/*you need an integer expression here*/];
Happy coding.
Here's an example of a 5x5 2-dimensional array:
The static part really makes no difference; just declare the member as static.