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(Object dest, Object src1, int length1, Object src2, int length2)
arraycopy
System.arraycopy(src1, 0, dest, 0, length1);
System.arraycopy(src2, 0, dest, length1, length2);
voidarrayCopy(Object src, int srcPos, Object dest, int destPos, int length)
Copies elements from the src array to the dest array.
if (length < 0 || srcPos < 0 || destPos < 0)
    throw new IndexOutOfBoundsException();
if (src instanceof Object[] && dest instanceof Object[]) {
    arrayCopy((Object[]) src, srcPos, (Object[]) dest, destPos, length);
} else if (src instanceof int[] && dest instanceof int[]) {
    arrayCopy((int[]) src, srcPos, (int[]) dest, destPos, length);
} else if (src instanceof boolean[] && dest instanceof boolean[]) {
    arrayCopy((boolean[]) src, srcPos, (boolean[]) dest, destPos, length);
...
voidarraycopy(Object src, int srcPos, Object dest, int destPos, int length)
Pases to System.arraycopy To bypass SecurityManager
System.arraycopy(src, srcPos, dest, destPos, length);
voidarrayCopy(Object[] source, Object[] target, int size)
Copy the elements of the source array to the target array.
if (size > MAX_JAVA_LOOP_COPY) {
    System.arraycopy(source, 0, target, 0, size);
} else {
    for (int i = 0; i < size; i++) {
        target[i] = source[i];
voidarraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length)
arraycopy
System.arraycopy(src, srcPos, dest, destPos, length);
String[]arraycopy(String[] src)
arraycopy
String[] copy = new String[src.length];
System.arraycopy(src, 0, copy, 0, src.length);
return copy;
voidarrayCopy(String[][] src, int src_position, String[][] dst, int dst_position, int length)
array Copy
System.arraycopy(src, src_position, dst, dst_position, length);
for (int i = src_position; i < src_position + length; i++) {
    String[] tem = new String[src[i].length];
    System.arraycopy(src[i], 0, tem, 0, tem.length);
    src[i] = tem;
T[]arraycopy(T[] a)
arraycopy
return Arrays.copyOf(a, a.length);
T[]arrayCopy(T[] objs)
Copy the given array.
if (objs == null)
    return null;
Object[] copy = new Object[objs.length];
System.arraycopy(objs, 0, copy, 0, objs.length);
return (T[]) copy;
voidarraycopy(T[] src, int srcPos, T[] dest, int destPos, int length)
Short-hand method for deciding whether or not to use the native System#arraycopy(Object,int,Object,int,int) method or an element-by-element copy, based on the #JNI_COPY_ARRAY_THRESHOLD .
if (length >= JNI_COPY_ARRAY_THRESHOLD) {
    System.arraycopy(src, srcPos, dest, destPos, length);
} else {
    for (int i = 0; i < length; i++) {
        dest[destPos + i] = src[srcPos + i];