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

voidarraycopy(T[] src, int srcPos, T[] dst, int len)
arraycopy
for (int i = 0; i < len; ++i)
    dst[i] = src[srcPos + i];
T[]arrayCopy(T[] x)
array Copy
return arrayCopy(x, true);
T[]arrayCopyAndAddEntry(T[] base, T extra)
array Copy And Add Entry
int last = base.length;
T[] tmp = Arrays.copyOf(base, last + 1);
tmp[last] = extra;
return tmp;
int[]arraycopyAndInsertInt(final int[] src, final int idx, final int value)
arraycopy And Insert Int
final int[] dst = new int[src.length + 1];
System.arraycopy(src, 0, dst, 0, idx);
dst[idx] = value;
System.arraycopy(src, idx, dst, idx + 1, src.length - idx);
return dst;
intarrayCopyToNull(T[] source, int sourceOffset, T[] destination, int destinationOffset)
Copies references from one array to another until it hits a null sentinel reference or the end of the source array.
int s;
for (s = 0; s + sourceOffset < source.length && source[s + sourceOffset] != null; s++)
    destination[s + destinationOffset] = source[s + sourceOffset];
return s;
voidarrayCopyWithRemoval(Object[] src, Object[] dst, int idxToRemove)
array Copy With Removal
if (src == null || dst == null || src.length - 1 != dst.length || idxToRemove < 0
        || idxToRemove >= src.length) {
    throw new IllegalArgumentException();
if (idxToRemove == 0) {
    System.arraycopy(src, 1, dst, 0, src.length - 1);
} else if (idxToRemove == src.length - 1) {
    System.arraycopy(src, 0, dst, 0, src.length - 1);
...
int[]Arrays_copyOf(int[] pos, int length)
GWT doesn't supply a Arrays.copyOf...
int[] result = new int[pos.length];
for (int i = 0; i < pos.length; i++)
    result[i] = pos[i];
return result;
byte[]copy(byte[] bytes)
This function creates a copy of a byte array.
byte[] result = Arrays.copyOf(bytes, bytes.length);
return result;
byte[]copy(byte[] data, int from)
Copy bytes.
return copy(data, from, data.length - from, (byte) 0x00);
double[][]copy(double[][] a)
Returns a deep copy of the given 2D array.
if (a.length == 0) {
    return new double[0][0];
double[][] c = new double[a.length][];
for (int i = 0; i < a.length; i++) {
    c[i] = Arrays.copyOf(a[i], a[i].length);
return c;
...