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

String[]subarrayOf(final String[] array, final int start, final int end)
Returns a new array with the elements between [start, end).
final int subarraySize = end - start;
final String[] subarray = new String[subarraySize];
for (int i = 0; i < subarraySize; ++i) {
    subarray[i] = array[i + start];
return (subarray);
byte[]subByteArray(byte[] array, int offset, int length)
sub Byte Array
int to = offset + length;
if (to > array.length)
    to = array.length;
return Arrays.copyOfRange(array, offset, to);
boolean[]subset(boolean[] array, int start, int end)
subset
if ((start < 0) || (end < 0) || ((end - start) < 0)) {
    return array;
boolean[] newArray = new boolean[end - start];
System.arraycopy(array, start, newArray, 0, end - start);
return newArray;
byte[]subset(byte[] a, int begin_index, int len)
subset
if (a == null)
    return null;
if (begin_index < 0 || len <= 0 || begin_index >= a.length || len > a.length - begin_index)
    throw new IllegalArgumentException("Wrong arguments: array length:" + a.length + ", begin index:"
            + begin_index + ", subset length:" + len);
byte[] b = new byte[len];
for (int i = 0; i < len; i++) {
    b[i] = a[i + begin_index];
...
byte[]subset(byte[] array, int start, int length)
subset
byte[] result = new byte[length];
System.arraycopy(array, start, result, 0, length);
return result;
char[]subset(final char[] array, final int start, final int length)
subset
char[] newArray = new char[length];
for (int i = 0; i < newArray.length; i++) {
    newArray[i] = array[i + start];
return newArray;
byte[]subset(int start, int count, byte[] source)
This is a quick method to get a subset of a byte array as a new array
byte[] ret = new byte[count];
for (int i = 0; i < count; i++) {
    ret[i] = source[start + i];
return ret;
String[]subset(String[] array, int starting, int width)
subset
String[] subset = new String[width];
System.arraycopy(array, starting, subset, 0, width);
return subset;
String[]subset(String[] in, int begin)
subset
String[] out;
int index = 0;
System.out.println(in.length);
out = new String[in.length - begin];
for (int l = begin; l < in.length; l++) {
    out[index] = in[l];
    index++;
return out;
String[]subset(String[] tokens, int offset)
Could be replaced by Arrays.copyOf in Java 1.6
int length = tokens.length - offset;
String[] result = new String[length];
for (int i = 0; i < length; i++)
    result[i] = tokens[i + offset];
return result;