This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

array declaration and creation  RSS feed

 
Alangudi Balaji Navaneethan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi



You can read this
or this for more information.
[ August 05, 2005: Message edited by: George Bolyuba ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!