Java Utililty Methods Array

List of utility methods to do Array

Description

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

Method

intarrayLookup(int[] ar, int keystart, int keyend, int forbidden)
Find first entry in integer array, whose value is in a given range.
for (int i = 0; ar != null && i < ar.length; i++)
    if (ar[i] >= keystart && ar[i] < keyend && ar[i] != forbidden)
        return i;
return -1;
booleanarrayMember(String[] array, String member)
array Member
for (int i = 0; i < array.length; i++) {
    if (array[i] != null && array[i].equals(member)) {
        return true;
return false;
double[]arrayMinus(double[] w, double[] v)
array Minus
double result[] = w.clone();
for (int i = 0; i < w.length; i++) {
    result[i] -= v[i];
return result;
voidarrayNotEmpty(T[] objects, String message)
Assert an array of T instances is not empty.
if (objects.length < 1) {
    throw new IllegalArgumentException(message);
Class[]arrayOfClassType(T... array)
array Of Class Type
Class<?>[] clazzs = new Class<?>[array.length];
for (int i = 0; i < array.length; i++) {
    clazzs[i] = array[i].getClass();
return clazzs;
StringarrayOffloatAsCSStrings(float[] ar)
array Offloat As CS Strings
String res = "";
for (int i = 0; i < ar.length - 1; i++) {
    res += Float.toString(ar[i]) + ",";
res += Float.toString(ar[ar.length - 1]);
return res;
StringarrayOffloatCoordsAsCSStrings(float[] ar)
array Offloat Coords As CS Strings
String res = "";
if (ar.length % 2 == 0) {
    for (int i = 0; i < ar.length - 2;) {
        res += Float.toString(ar[i]) + "," + Float.toString(ar[i + 1]) + ";";
        i += 2;
    res += Float.toString(ar[ar.length - 2]) + "," + Float.toString(ar[ar.length - 1]);
return res;
booleanarrayPrefixEqual(byte[] a1, int off1, byte[] a2, int off2, int len)
array Prefix Equal
if (off1 + len > a1.length)
    return false;
if (off2 + len > a2.length)
    return false;
for (int i = 0; i < len; i++)
    if (a1[off1 + i] != a2[off2 + i])
        return false;
return true;
...
StringarrayPrint(T[] arr)
array Print
String retval = "[" + arr[0].toString();
for (int i = 1; i < arr.length; i++) {
    retval = retval + ", " + arr[i];
retval = retval + "]";
return retval;
voidarrayPrint(T[] x)
array Print
arrayPrint(x, "\n", true);