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

E[]subArray(E[] array, int start)
sub Array
return subArray(array, start, array.length);
byte[]subArray(final byte[] source, final int start, final int length)
Works like String.substring()
if (start < 0) {
    throw new ArrayIndexOutOfBoundsException("Start index: " + start);
if (source == null) {
    throw new IllegalArgumentException("Source array was null");
if ((start + length) > source.length) {
    throw new ArrayIndexOutOfBoundsException("length index: " + length);
...
byte[]subArray(final byte[] src, final int srcPos, final int length)
Devuelve una porción del array especificado.
if (length == 0) {
    return null;
if (src.length < srcPos + length) {
    return null;
final byte[] temp = new byte[length];
System.arraycopy(src, srcPos, temp, 0, length);
...
char[]subArray(final char[] source, int from, int to)
Best for arrays less than 20 cells
char[] target = new char[to - from + 1];
for (int i = 0; i < target.length; i++) {
    target[i] = source[from + i];
return target;
int[]subArray(final int[] input, final int start, final int end)
Generates a subarray of a given int array.
int[] result = new int[end - start];
System.arraycopy(input, start, result, 0, end - start);
return result;
long[]subArray(final long[] array, final int start, final int end)
sub Array
final int length = end - start;
if (length < 0)
    throw new IllegalArgumentException();
final long[] result = new long[length];
System.arraycopy(array, start, result, 0, length);
return result;
long[]subarray(final long[] array, int startIndexInclusive, int endIndexExclusive)

Produces a new long array containing the elements between the start and end indices.

if (array == null) {
    return null;
if (startIndexInclusive < 0) {
    startIndexInclusive = 0;
if (endIndexExclusive > array.length) {
    endIndexExclusive = array.length;
...
String[]subarray(final String[] arr, int first, final int last)
Removes some elements from a String array.
final String[] newArr = new String[last - first + 1];
for (int i = 0; i < newArr.length; ++i, ++first) {
    newArr[i] = arr[first];
return newArr;
float[]subArray(float[] array, int start)
sub Array
int nl = array.length - start;
float[] ret = new float[nl];
for (int q = start; q < array.length; q++) {
    ret[q - start] = array[q];
return ret;
int[]subarray(int[] array, int offset, int length)
subarray
if (offset > array.length - 1 || offset + length > array.length)
    return new int[] {};
int select[] = new int[length];
for (int i = 0; i < length; i++)
    select[i] = array[offset + i];
return select;