[Solved] Unexpected result when copying an array in Java


System.arraycopy(scores, 2, scores, 3, 2);

This copies 2 items from source index 2. therefore {3, 4} into destination position 3. Since your source and destination arrays are the same you’re overwriting the 5 with the 4

          {3  4}      <== items copied
{ 1, 2, 3, 4, 5, 6}   <== original

  0  1  2  3  4  5    <== indexes

{ 1, 2, 3, 3, 4, 6}   <== output, the 4 has overwritten the 5, damn

1

solved Unexpected result when copying an array in Java