File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array

 
Netty poestel
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's something I'm stumbling with



and the command-line invocation,
java CommandArgsThree 1 2 3
Q-->what is the result?

I'm not being able to interpret this code.
from intial feedbacks this is how I'm seeing the picture


each element in "argcopy" contains an array of 2 elements as shown
above 'argcopy' [ could not draw the linking lines properly....too painful ]
considering 'x = argCopy[0].length;' should be 3 , what is happening with

System.out.print(" " + argCopy[0][y]); // in terms of the boxes I have
drawn. If at all I have drawn them in the proper way.

TIA

( tags added and an attempt to format the code)
[ November 10, 2004: Message edited by: Barry Gaunt ]
 
Atul Chandran
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
5. argCopy[0] = args;

after this line argCopy[0] will be refering to the array of length 3 which is reffered to by arg.

before line 5
argcopy[0]-------->[null] [null] /*an array of length 2 whose elements are initialized to null.*/


after line 5.
argcopy[0]-------->["1"] ["2"] ["3"]//an array of length 3 .

[ November 10, 2004: Message edited by: Atul Chandran ]

[ November 10, 2004: Message edited by: Atul Chandran ]
[ November 10, 2004: Message edited by: Atul Chandran ]
 
Netty poestel
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Atul Chandran:
5. argCopy[0] = args;

after this line argCopy[0] will be refering to a new array of length 3.

before line 5
argcopy[0]-------->[0] [0] //an array of length 2 initialized to 0.


after line 5.
argcopy[0]-------->[1] [2] [3]//an array of length 3.

[ November 10, 2004: Message edited by: Atul Chandran ]

[ November 10, 2004: Message edited by: Atul Chandran ]



Howdy..

(i)
"before line 5 argcopy[0]-------->[0] [0] an array of length 2 initialized to 0."

since it's a String array, shouldn't that be initialized as a null ?


(ii)
"after this line argCopy[0] will be refering to a new array of length 3."

would this mean that argcopy is now referring 'also' to a 3rd new array. ? so are the original 2 are stll connected at this point ?

Thx.
 
Atul Chandran
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry my mistake ...you are right..I have editided my post...Didn't look at the code closely.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic