Reputation: 1390
What is wrong with this definition? I want to declare a two dimensional array with those numbers:
int[][] arr = [[1,2,3],[1,2,3],[1,2,3]];
I get this error:
Type mismatch: cannot convert from int to int[]
Upvotes: 2
Views: 138
Reputation: 664
It should be like so:
int[][] arr = {{1,2,3},{1,2,3},{1,2,3}};
Yout need to use curly brakets ({ }
).
Upvotes: 3
Reputation: 1529
You should use {
and }
, instead of [
and ]
to initialize the array.
Upvotes: 3
Reputation: 95968
Should be:
int[][] arr = {{1,2,3},{1,2,3},{1,2,3}};
More information is available on JLS, see 10.6. Array Initializers:
An array initializer is written as a comma-separated list of expressions, enclosed by braces { and }.
You might also want to have a look at a basic tutorial, it'll help you a lot.
Upvotes: 7