There are two ways to copy an array in Java:
A: System.arraycopy (original array, start copy of the subscript, the copy contents of the array, start to store the subscript, the length of the copy is required);
This method requires creating an empty array that holds the copy content, and then copying the original array into the new array.
int [] arr = {1,2,3,4,5}; int New int [ten]; 0 1 5); // 5 is the length to copy System. out. println (arrays.tostring (copied));
Two: arrays.copyof (original array, copy of the array length);
Can be used to expand and shrink, do not need to first create an array, but actually also created a new I array, the bottom is called system.arraycopy () method;
int[] copied = arrays.copyof (arr, 10); The length of the new array System.out.println (arrays.tostring (copied)); copied = arrays.copyof (arr, 3); System.out.println (arrays.tostring (copied));
Two ways to copy arrays in Java