aspose file tools*
The moose likes Beginning Java and the fly likes Array declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array declaration" Watch "Array declaration" New topic
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: 19760
    
  20

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 - OCEEJBD 6
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
 
wood burning stoves
 
subject: Array declaration