This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array declaration and creation" Watch "array declaration and creation" New topic
Author

array declaration and creation

Alangudi Balaji Navaneethan
Ranch Hand

Joined: Apr 28, 2004
Posts: 42
Hi,

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

Thanks
Shyam Ramineni


<a href="http://hyderabaditeducation.com" target="_blank" rel="nofollow">http://hyderabaditeducation.com</a>
Georgy Bolyuba
Ranch Hand

Joined: Feb 18, 2005
Posts: 162
Hi



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)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: array declaration and creation