File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array declaration and creation 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 and creation" Watch "array declaration and creation" New topic

array declaration and creation

Alangudi Balaji Navaneethan
Ranch Hand

Joined: Apr 28, 2004
Posts: 42

I have a doubt in the following code. Please clear my doubt

Upto line 3 I have no problem. I well understood the concept behind them. The compiler generated error messages at line 4 and line 5 saying illegal start of expression.
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580

array2[0] = {1,2,3,4,5}; // line 4
array2[1] = {6,7,8,9,10}; // line 5

array2 is a Two dimensional array
array2[0] - holds only address of a one dimensional array or null
array2[0][0] - holds only values

but in the above case you are assigning values where it is expecting address
changte it to

array2[0][0] = {1,2,3,4,5}; // line 4
array2[0][1] = {6,7,8,9,10}; // line 5
shyam ramineni
Ranch Hand

Joined: Jul 08, 2005
Posts: 43
Hi Vidya,

array2[0][0] = {1,2,3,4,5}; // line 4
array2[0][1] = {6,7,8,9,10}; // line 5

The above code change you have suggested did not work.
Below is the code that works. But I donot know the reason behind it.

When we are creating anynomous array and assign that reference to
array2[0] its working.

Can anyone please tell what differnce between line1 and line2, and when to use which one.
int[] a1 = {1,1,1,1}; //line1
int[] a1 = new int[] {1,1,1,1}; // line2

Shyam Ramineni

<a href="" target="_blank" rel="nofollow"></a>
Georgy Bolyuba
Ranch Hand

Joined: Feb 18, 2005
Posts: 162

You can read this
or this for more information.
[ August 05, 2005: Message edited by: George Bolyuba ]

SCJP 1.4 (100%) Done.<br />SCJD (URLyBird 1.2.3 Started)
I agree. Here's the link:
subject: array declaration and creation
It's not a secret anymore!