Java Utililty Methods Array Copy

List of utility methods to do Array Copy

Description

The list of methods to do Array Copy are organized into topic(s).

Method

char[][]copy2DArray(char[][] original)
copy D Array
char[][] result = new char[original.length][];
for (int i = 0; i < original.length; i++) {
    result[i] = Arrays.copyOf(original[i], original[i].length);
return result;
char[][][][][]copy5DArray(char[][][][][] original)
copy D Array
char[][][][][] result = new char[original.length][][][][];
for (int i = 0; i < original.length; i++) {
    result[i] = new char[original[i].length][][][];
    for (int j = 0; j < original[i].length; j++) {
        result[i][j] = new char[original[i][j].length][][];
        for (int k = 0; k < original[i][j].length; k++) {
            result[i][j][k] = copy2DArray(original[i][j][k]);
return result;
T[]copyAndFillOf(T[] original, int newLength, T padding)
copy And Fill Of
if (newLength < 0)
    throw new NegativeArraySizeException("The array size is negative.");
T[] newArray = Arrays.copyOf(original, newLength);
if (original.length < newLength) {
    System.arraycopy(original, 0, newArray, 0, original.length);
    Arrays.fill(newArray, original.length, newArray.length, padding);
} else
    System.arraycopy(original, 0, newArray, 0, newLength);
...
int[]copyArray()
copy Array
int[] array = new int[10];
for (int i = 0; i < array.length; i++) {
    array[i] = (int) (Math.random() * 10);
int[] newArray = new int[array.length];
for (int i = 0; i < array.length; i++) {
    newArray[i] = array[i];
System.out.println("Original Array: ");
for (int i = 0; i < array.length; i++) {
    System.out.println(array[i]);
System.out.println("New Array:");
for (int i = 0; i < array.length; i++) {
    System.out.println(newArray[i]);
return newArray;
voidcopyArray(byte[] dest, int off, byte[] src)
copy Array
System.arraycopy(src, 0, dest, off, src.length);
byte[]copyArray(byte[] original, int start, int length)
copy Array
byte[] copy = new byte[length];
System.arraycopy(original, start, copy, 0, Math.min(original.length - start, length));
return copy;
intcopyArray(byte[] out, byte[] in, int idx)
copy Array
for (int i = in.length - 1; i >= 0; i--)
    out[idx + i] = in[i];
return in.length;
double[]copyArray(double[] a)
Returns a copy of the specified array.
if (a != null) {
    return copyArray(a, a.length);
} else {
    return null;
double[]copyArray(double[] array)
Creates a copy of the given array.
double[] retVal = new double[array.length];
System.arraycopy(array, 0, retVal, 0, array.length);
return retVal;
voidcopyArray(double[] src, double[] dest, int len)
copy Array
int i;
for (i = 0; i < len; i++) {
    dest[i] = src[i];