File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes multidimensional arrrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "multidimensional arrrays " Watch "multidimensional arrrays " New topic
Author

multidimensional arrrays

ram shah
Greenhorn

Joined: Jun 02, 2007
Posts: 28
int[] a, b[];
In the above code snippet, a is a single dimensional array & b is 2 dimensional array....Am I right?

Pls correct me if I'm wrong.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18757
    
  40

Correct. "a" is an array of ints. "b" is an array of arrays of ints.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Here's an excerpt from my notes...
When declaring an Array, the identifier can appear anywhere amid the pairs of brackets denoting the dimension (but not enclosed within brackets). For example...

String s[][];
String []s[];
String [][]s;

When an Array of a given type and dimension is declared, any subsequent identifiers on that line can add dimensions -- provided that the brackets indicating the additional dimensions come after the associated identifier.

int[][]a, b, c[];

In the above declaration, a and b are both declared as 2-dimensional Arrays, while c adds a dimension to become a 3-dimensional Array.

Note, however, that in the declaration below, d is a 2-dimensional Array (an Object), while e remains a primitive int.

int d[][], e;


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
yogesh srinivasan
Ranch Hand

Joined: Jun 08, 2007
Posts: 55
cote

Note, however, that in the declaration below, d is a 2-dimensional Array (an Object), while e remains a primitive int.

int d[][], e;


Why in the above declaration e is not a 2-d array ??
anshi kohli
Ranch Hand

Joined: Jun 30, 2007
Posts: 35
what if int[][]d, e; was there then d and e both are 2-D arrays???
Manfred Klug
Ranch Hand

Joined: Jun 04, 2007
Posts: 377
Originally posted by anshi kohli:
what if int[][]d, e; was there then d and e both are 2-D arrays???
Yes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multidimensional arrrays