Java Utililty Methods Array Sub Array

List of utility methods to do Array Sub Array

Description

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

Method

byte[]subArray(byte[] byteArray, int beginIndex, int length)
Returns a portion of the specified byte array.
byte[] subArray = new byte[length];
System.arraycopy(byteArray, beginIndex, subArray, 0, subArray.length);
return subArray;
byte[]subArray(byte[] data, int offset, int length)
Returns subarray of bytes.
byte[] subarray = new byte[length];
System.arraycopy(data, offset, subarray, 0, length);
return subarray;
byte[]subArray(byte[] data, int offset, int length)
sub Array
if (length == -1 || length > data.length - offset) {
    length = data.length - offset;
byte[] returnValue = new byte[length];
for (int i = 0; i < length; i++) {
    returnValue[i] = data[i + offset];
return returnValue;
...
byte[]subarray(byte[] in, int a, int b)
Creates and returns a new array with the values of the original from index a to index b and of size (b-a).
if (b - a > in.length)
    return in;
byte[] out = new byte[(b - a) + 1];
for (int i = a; i <= b; i++) {
    out[i - a] = in[i];
return out;
byte[]subarray(byte[] in, int arg1, int arg2)
subarray
byte[] out = new byte[(arg2 - arg1) + 1];
if (arg2 - arg1 > in.length) {
    return in;
for (int i = arg1; i <= arg2; i++) {
    out[i - arg1] = in[i];
return out;
...
byte[]subArray(byte[] in, int start, int end)
Returns a sub-array of the input array with range specified by the starting (inclusive) and ending (exclusive) indices.
int N = end - start;
byte[] out = new byte[N];
for (int i = 0; i < N; i++) {
    out[i] = in[i + start];
return out;
byte[]subArray(byte[] input, int start)
Generate a subarray of a given byte array.
return subArray(input, start, input.length);
byte[]subArray(byte[] source, int start, int len)
sub Array
if (start < 0) {
    start = 0;
if (len < 0 || len > source.length) {
    return null;
byte[] result = new byte[len];
for (int i = 0; i < len; i++) {
...
byte[]subarray(byte[] src, int beginIndex)
subarray
if (beginIndex == 0) {
    return src;
byte[] res = new byte[src.length - beginIndex];
System.arraycopy(src, beginIndex, res, 0, res.length);
return res;
byte[]subArray(byte[] src, int offset, int len)
sub Array
if (offset == 0 && len == src.length)
    return src;
if ((offset < 0 || offset >= src.length) || (offset + len > src.length))
    throw new IllegalArgumentException("Copy range out of array bounds");
byte[] dest = new byte[len];
System.arraycopy(src, offset, dest, 0, len);
return dest;