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

byte[]cloneByteArray(byte[] b)
Create a new byte array and copy all the data.
if (b == null) {
    return null;
int len = b.length;
if (len == 0) {
    return b;
byte[] copy = new byte[len];
...
byte[]cloneBytes(byte[] buffer)
clone Bytes
byte[] ret = new byte[buffer.length];
System.arraycopy(buffer, 0, ret, 0, buffer.length);
return ret;
char[]cloneCharArray(char[] chars)
Create a new char array and copy all the data.
if (chars == null) {
    return null;
int len = chars.length;
if (len == 0) {
    return chars;
char[] copy = new char[len];
...
double[][]cloneDoubleMatrix(double[][] src)
clone Double Matrix
int rows = src.length;
double[][] clone = new double[rows][];
for (int r = 0; r < rows; r++) {
    int cols = src[r].length;
    clone[r] = new double[cols];
    for (int c = 0; c < cols; c++) {
        clone[r][c] = src[r][c];
return clone;
int[]cloneIntArray(int array[])
Clone an integer array.
int i, n;
int[] arrayNew;
if (array == null)
    return null;
n = array.length;
arrayNew = new int[n];
for (i = 0; i < n; i++) {
    arrayNew[i] = array[i];
...
long[]cloneLong(long[] array)
clone Long
if (array == null) {
    return null;
return (long[]) array.clone();
double[]cloneNonNullArray(double[] array)
Returns a copy of array or #EMPTY_DOUBLE_ARRAY if empty.
return array.length == 0 ? EMPTY_DOUBLE_ARRAY : array.clone();
byte[]cloneSubarray(byte[] array, int offset, int len)
Creates a copy of byte array.
byte[] data = new byte[len];
System.arraycopy(array, 0, data, offset, len);
return data;
byte[]cloneSubArray(byte[] data, int offset, int size)
This method allows a subsection of a byte array to be copied.
byte[] newData = new byte[size];
System.arraycopy(data, offset, newData, 0, size);
return (newData);
int[]cloneTest(int[] test)
clone Test
int[] rval = new int[test.length];
for (int i = 0; i < test.length; i++) {
    rval[i] = test[i];
return rval;