| Author |
multi-dimensional array question
|
Joe McGuire
Ranch Hand
Joined: Mar 19, 2001
Posts: 293
|
|
I have an interesting question that arose while trying to help someone in another forum. The following code: int[][] a = { { 1 , 2 } , { 1 , 2 } } ; compiles, of course, without problem. However, if we split the declaration and the initialization, it fails: int[][] a ; a = { { 1 , 2 } , { 1 , 2 } } ; In single-dimensional arrays this is no problem. Why doesn't it work with multi-dimensional arrays?
|
 |
Mike Curwen
Ranch Hand
Joined: Feb 20, 2001
Posts: 3695
|
|
If you try to do this: it gives an 'illegal start of expression' for the opening brace. I think this syntax can only be used during declarative initialization. Otherwise, you must explicity initialize each array element (and this goes for both 1 and n-dimensional arrays.)
|
 |
rani bedi
Ranch Hand
Joined: Feb 06, 2001
Posts: 358
|
|
|
Array constants can only be used in initializers.
|
Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
|
 |
 |
|
|
subject: multi-dimensional array question
|
|
|