Java Utililty Methods Array Range Copy

List of utility methods to do Array Range Copy

Description

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

Method

T[]copyOf(T[] oriArray, int newArraySize, int startOffset)
Generates an copy of the array with some size modification.
Object[] targetArray = new Object[newArraySize];
if (oriArray != null) {
    for (int i = startOffset, count = 0; i < newArraySize && count < oriArray.length; ++i, ++count) {
        targetArray[i] = oriArray[count];
return (T[]) targetArray;
int[]copyOfArray(int[] a)
copy Of Array
int[] result = new int[a.length];
for (int i = 0; i < result.length; i++) {
    result[i] = a[i];
return result;
byte[]copyOfRange(byte[] bytes, int offset, int len)
copy Of Range
byte[] result = new byte[len];
System.arraycopy(bytes, offset, result, 0, len);
return result;
byte[]copyOfRange(byte[] original, int from, int to)
Copies the specified range of the specified array into a new array.
int newLength = to - from;
if (newLength < 0)
    throw new IllegalArgumentException(from + " > " + to);
byte[] copy = new byte[newLength];
System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
return copy;
byte[]copyOfRange(byte[] original, int from, int to)
Copies the specified range of the specified array into a new array.
int newLength = to - from;
if (newLength < 0)
    throw new IllegalArgumentException(from + " > " + to);
byte[] copy = new byte[newLength];
System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
return copy;
byte[]copyOfRange(byte[] original, int from, int to)
Makes a new byte[] as a subset of an original given one.
int newLength = to - from;
if (newLength < 0)
    throw new IllegalArgumentException(from + " > " + to);
byte[] copy = new byte[newLength];
System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
return copy;
byte[]copyOfRange(byte[] original, int from, int to)
copy Of Range
if (from >= original.length || to > original.length || to <= from) {
    return null;
int newLength = to - from;
byte[] copy = new byte[newLength];
System.arraycopy(original, from, copy, 0, newLength);
return copy;
byte[]copyOfRange(byte[] original, int from, int to)
copy Of Range
checkCopyOfRangeParams(original, from, to);
int newLength = to - from;
if (newLength < 0)
    throw new IllegalArgumentException(from + " > " + to);
byte[] copy = new byte[newLength];
System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
return copy;
char[]copyOfRange(char[] original, int from, int to)
Copies the specified range of the specified array into a new array.
int newLength = to - from;
if (newLength < 0)
    throw new IllegalArgumentException(from + " > " + to);
char[] copy = new char[newLength];
System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
return copy;
byte[]copyOfRange(final byte[] array, final int startIndex, final int endIndex)
copy Of Range
int len = endIndex - startIndex;
if (len <= 0) {
    return new byte[0];
final byte[] result = new byte[len];
System.arraycopy(array, startIndex, result, 0, len);
return result;