Java Utililty Methods Array Clone

List of utility methods to do Array Clone

Description

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

Method

int[]clone(int[] array)
clone
if (array == null) {
    return null;
return (int[]) array.clone();
int[]clone(int[] array)
Return a clone of the given int array.
int[] result = new int[array.length];
System.arraycopy(array, 0, result, 0, array.length);
return result;
int[]clone(int[] in)
clone
int nx = in.length;
int[] out = new int[nx];
for (int i = 0; i < nx; i++) {
    out[i] = in[i];
return out;
int[]clone(int[] src)
clone
int[] dest = new int[src.length];
System.arraycopy(src, 0, dest, 0, src.length);
return dest;
int[]clone(int[] src, int[] dest)
Copies source array content to destination array.
if (src.length != dest.length) {
    throw new IllegalArgumentException("Arrays differ in sizes!");
System.arraycopy(src, 0, dest, 0, src.length);
return dest;
Object[]clone(Object[] array)
clone
return (array != null) ? array.clone() : new Object[0];
Object[]clone(Object[] array)
clone
return array == null ? null : (Object[]) ((Object[]) array.clone());
Object[]clone(Object[] array)

Shallow clones an array returning a typecast result and handling null.

The objects in the array are not cloned, thus there is no special handling for multi-dimensional arrays.

This method returns null for a null input array.

if (array == null) {
    return null;
return (Object[]) array.clone();
Object[]clone(Object[] source)
clone
if (source == null) {
    return null;
Object[] dest = new Object[source.length];
for (int i = 0; i < source.length; i++) {
    dest[i] = source[i];
return dest;
...
Object[]clone(Object[] src, Object[] trg)
clone
for (int i = 0; i < src.length; i++) {
    trg[i] = src[i];
return trg;