This week's book giveaway is in the OCAJP 8 forum.We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!See this thread for details.
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!

# Is this valid?

K Ville
Ranch Hand

Joined: Aug 16, 2003
Posts: 58
Given:
int[] a1[],a2[];

It seems to me that the 1st array obj ref is a 2d array, and the 2nd one is a simple array.

Thinking is the talking of the soul with itself...-Plato
K Ville
Ranch Hand

Joined: Aug 16, 2003
Posts: 58
Got a follow-up from a mock I'm presently taking.
Given:
int[][] a = {{1,2,3},{4,5,6},{7,8,9,10}};
Is this also valid? Is it not that the 2nd pair of curly braces must be a set of parentheses?
Anupreet Arora
Ranch Hand

Joined: Jun 17, 2003
Posts: 81
Given:
int[] a1[],a2[];
It seems to me that the 1st array obj ref is a 2d array, and the 2nd one is a simple array.

Well both of them are 2D arrays. What you say would have been true if the declaration had been sth like:
int[] a1[],a2;
Given:
int[][] a = {{1,2,3},{4,5,6},{7,8,9,10}};
Is this also valid? Is it not that the 2nd pair of curly braces must be a set of parentheses?

Yes, this is valid as is this how multidimesional arrays are declared and contructed, using curly braces and not parenthesis.
Regards,
Anupreet
K Ville
Ranch Hand

Joined: Aug 16, 2003
Posts: 58
Thanks so much! But do you also mean that:

int[] a1[], a2
is a valid declaration? IF so, I never knew this. It would be a great help from you. God bless!
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

Yes it is! a1 is a 2 D array and a2 is a 1-D array!
Originally posted by K Ville:
Thanks so much! But do you also mean that:

int[] a1[], a2
is a valid declaration? IF so, I never knew this. It would be a great help from you. God bless!

[ September 02, 2003: Message edited by: Pradeep Bhat ]

Groovy
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

check out this thread that just came up a couple weeks ago, it might help some more:
2 D Arrays

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Munish Gulati
Ranch Hand

Joined: Aug 06, 2003
Posts: 37
And one more thing about the above discussion...now as you know
int[] a1[], a2; is a valid declaration so assignments
a1=a2;
or
a2=a1;
will result in a compiler error.
while in case int[] a1[],a2[] both a1 and a2 are 2D arrays so
a1=a2;
or
a2=a1;
are valid.
[ September 02, 2003: Message edited by: Thomas Paul ]
[ September 02, 2003: Message edited by: Karan Gulati ]

Munish Gulati<br />SCJP 1.4<br />Albert Einstein: There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.

I agree. Here's the link: http://aspose.com/file-tools

subject: Is this valid?