Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What about arrays?

 
Snylt Master
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy!
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
Cheers


------------------
Preparing for the Java 2 Certification exam
 
Detlev Beutner
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Detlev
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic