About Question enthuware.ocajp.i.v7.2.878 :
Posted: Mon Dec 02, 2013 5:00 pm
int[] scores = { 1, 2, 3, 4, 5, 6};
System.arraycopy(scores, 2, scores, 3, 2);
for(int i : scores) System.out.print(i);
I don't understand how the correct answer can be 123346. Signature for arraycopy is:
public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length)
System.arraycopy(scores, 2, scores, 3, 2) is in English: copy 1 (2-1) item from the 3rd position (index 2) of the 'scores' array to the 4th (index 3) position of the same array.
So from 1,2,3,4,5,6 I copy item with value 3 to position 4 and I get 1,2,3,3,4,5,6. Array is immutable and I assume that 6 'falls off'. This gives me 1,2,3,3,4,5 and not 1,2,3,3,4,6
System.arraycopy(scores, 2, scores, 3, 2);
for(int i : scores) System.out.print(i);
I don't understand how the correct answer can be 123346. Signature for arraycopy is:
public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length)
System.arraycopy(scores, 2, scores, 3, 2) is in English: copy 1 (2-1) item from the 3rd position (index 2) of the 'scores' array to the 4th (index 3) position of the same array.
So from 1,2,3,4,5,6 I copy item with value 3 to position 4 and I get 1,2,3,3,4,5,6. Array is immutable and I assume that 6 'falls off'. This gives me 1,2,3,3,4,5 and not 1,2,3,3,4,6