File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes What about arrays? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What about arrays?" Watch "What about arrays?" New topic

What about arrays?

Snylt Master
Ranch Hand

Joined: Jul 07, 2001
Posts: 55
I have some problems with arrays.... ( still? ). Consider the following code
1. int i[5][];
2. int i[][];
3. int []i[];
4. int i[5][5];
5. int[][] a;
My notes:
1 is illegal because the array must be initialized: int i[][] = new int[5][]
2. Perfectly legal.
3. Here's my problem. Is this array one or two dimentional. Can anyone please clear this out for me.
4. Not legal
5. legal

Preparing for the Java 2 Certification exam

Preparing for the Java 2 Certification exam
Detlev Beutner
Ranch Hand

Joined: Jul 13, 2001
Posts: 76
Two-dimensional. Look at the Java Language Specification, chapter 10.2:
The [] may appear as part of the type at the beginning of the declaration, or as part of the declarator for a particular variable, or both, as in this example:
byte[] rowvector, colvector, matrix[];
This declaration is equivalent to:
byte rowvector[], colvector[], matrix[][];
Hope it helps
I agree. Here's the link:
subject: What about arrays?
It's not a secret anymore!