First type:
把一个数组的值拷贝到另一个数组 public static int[] copyArray(int[] array){ int[] copy = new int[array.length]; for (int i = 0; i <array.length ; i++) { copy[i] = array[i]; } return copy; } public static void main(String[] args) { int[] array = {1,4,6,3,8,9}; int[] ret = copyArray(array); System.out.println(Arrays.toString(ret)); }
Print result:
Second type:
Copy array (self) function
Print result:
The length can also be multiplied by 2, but not in the original On the basis of expanding 2 times, here is a new object
Copy array (part) function:
All source codes in Java from and to are left-closed and right-open.
The third type:
Print result:
The fourth copy:
The above is the detailed content of How to copy an array in java. For more information, please follow other related articles on the PHP Chinese website!