I would like to do a deep copy of a primitive array of n dimensions.
public static double[] deepCopy(double[] arr) {
return arr.clone();
}
public static double[][] deepCopy(double[][] arr) {
arr = arr.clone();
for (int i = 0; i < arr.length; i++) {
arr[i] = deepCopy(arr[i]);
}
return arr;
}
public static double[][][] deepCopy(double[][][] arr) {
arr = arr.clone();
for (int i = 0; i < arr.length; i++) {
arr[i] = deepCopy(arr[i]);
}
return arr;
}
Above is the code to deep copy a double array of 1, 2, and 3 dimensions. I would like to generalize for any primitive type and/or generalize for the dimension of the array. I would like both, but I know a lot of things in Java are not possible, so it is okay if you can only get one, or tell me why it wouldn't work.
Thank you!