aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array declaration " Watch "array declaration " New topic
Author

array declaration

Brian Spindler
Greenhorn

Joined: May 17, 2007
Posts: 29
can someone explain why b gets a two dimensional declaration in this code:



Nevermind foo and bar; they are my examples to prove the point visually.
Duc Vo
Ranch Hand

Joined: Nov 20, 2008
Posts: 254
because (note the comma separator)


is equivalent to


or


“Everything should be as simple as it is, but not simpler.” Albert Einstein
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 791

Also following code is



equivalent to



and another way is


is equivalent to



SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Arka Guhathakurta
Ranch Hand

Joined: Mar 01, 2009
Posts: 46
A few tips about array.....


The above code will declare two arrays of int primitive type.

This code will declare an int array named arr1 and another int variable named arr2.
so if you write something like this...


will probably declare a two dimensional array named b.


regards,
Arka
Brian Spindler
Greenhorn

Joined: May 17, 2007
Posts: 29
I think it's becoming much clearer now; it's really about the placement of the [] in regards to the association of the variable.

Thanks all!
Shin Kudo
Greenhorn

Joined: Apr 17, 2009
Posts: 25
[] when appears behind the type applies to all variables in this declaration,
[] when appears behind a variable only applies to that particular variable.

You can see example from Arka Guhathakurta's post.


SCJP 6 - SCWCD in progress...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array declaration