| Author |
Array declaration
|
roshni bhagat
Greenhorn
Joined: Jan 31, 2008
Posts: 6
|
|
Is this declaration correct: int[] arr = new int[5][];
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
No it isn't. The declared type is int[] - array of integers. The initialized type is int[][] - array of array of integers. So either add a [] in the declaration, or remove the [] (keep the [5]) in the initialization.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
No. Doesn't your compiler tell you this? creates a variable which references a one dimensional array of primitive integers. creates a two dimensional array of primitive integers. You can't assign one to the other.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
 |
|
|
subject: Array declaration
|
|
|