Originally posted by Henry Wong:
Just in case the OP was under the impression that the following...
s=args;
does an element by element assignment, it does not. To do a copy of the elements of the array into another array, you should use the System.arraycopy() method.
Henry
Or to put it differently again:
defines an object reference which is able to point at
String arrays, and at time of creation it happens to point at an String array object with a dimension of 2. Then the object to which s is pointing is changed by this line:
Now args is a String array as well, and since s was defined to point at String arrays, the assignment is correct (the original String array is likely to be gc-fodder), and the program runs happily.