The list of methods to do Array Range Copy are organized into topic(s).
boolean[]
copyOf(boolean[] array, int length) Returns a copy of the given array of size 1 greater than the argument.
boolean[] anew = new boolean[length];
for (int i = 0; i < length; i++) {
if (i < array.length) {
anew[i] = array[i];
continue;
anew[i] = false;
return anew;
byte[]
copyOf(byte[] b) Creates a copy of the given byte array.
if (b == null) {
return null;
return copyOf(b, 0, b.length);
byte[]
copyOf(byte[] b, int off, int len) Creates a copy of a section of the given byte array.
if (b == null) {
throw new NullPointerException();
if (off < 0 || len < 0 || off > b.length - len) {
throw new ArrayIndexOutOfBoundsException();
byte[] copy = new byte[len];
System.arraycopy(b, off, copy, 0, len);
...
byte[]
copyOf(byte[] bytes, int startIndex, int length) Returns a new byte array of 'length' size containing the contents of the provided 'bytes' array beginning at startIndex to (startIndex+length-1)
byte[] newByteArray = new byte[length];
for (int i = 0; i < length; i++) {
newByteArray[i] = bytes[i + startIndex];
return newByteArray;
byte[]
copyOf(byte[] original, int newLength) Replacement for Java6 Arrays#copyOf(byte[],int) .
byte[] result = new byte[newLength];
System.arraycopy(original, 0, result, 0, Math.min(newLength, original.length));
return result;
byte[]
copyOf(byte[] original, int newLength) Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
byte[] copy = new byte[newLength];
System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
return copy;
byte[]
copyOf(byte[] original, int newLength) copy Of
if (newLength < 0) {
throw new IllegalArgumentException();
byte[] buf = new byte[newLength];
int lastIndex = Math.min(original.length, newLength);
System.arraycopy(original, 0, buf, 0, lastIndex);
return buf;