Java Utililty Methods Array Range Copy

List of utility methods to do Array Range Copy

  1. HOME
  2. Java
  3. A
  4. Array Range Copy

Description

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

Method

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[] arr, int newLength)
Returns a copy of the given array of the given length.
return copyOf(arr, 0, newLength, 0);
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)
copy Of
if (off == 0 && len == b.length)
 return b;
byte[] br = new byte[len];
System.arraycopy(b, off, br, 0, len);
return br;
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)
copy Of
return copyOfRange(bytes, 0, bytes.length);
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;


AltStyle によって変換されたページ (->オリジナル) /