If you think the Android project droid-fu listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.github.droidfu.support;
/*www.java2s.com*/import java.lang.reflect.Array;
publicclass ArraySupport {
@SuppressWarnings("unchecked")
publicstatic <T> T[] join(T[] head, T[] tail) {
if (head == null) {
return tail;
}
if (tail == null) {
return head;
}
Class<?> type = head.getClass().getComponentType();
T[] result = (T[]) Array.newInstance(type, head.length + tail.length);
System.arraycopy(head, 0, result, 0, head.length);
System.arraycopy(tail, 0, result, head.length, tail.length);
return result;
}
@SuppressWarnings("unchecked")
publicstatic <T> T[] delete(T[] array, int index) {
int length = array.length;
if (index < 0 || index >= length) {
thrownew IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
}
T[] result = (T[]) Array.newInstance(array.getClass().getComponentType(), length - 1);
System.arraycopy(array, 0, result, 0, index);
if (index < length - 1) {
System.arraycopy(array, index + 1, result, index, length - index - 1);
}
return result;
}
/**
* Attempts to find an object in a potentially unsorted array. Complexity is
* O(N).
*
* @param <T>
* @param array
* the input array
* @param object
* the object to find
* @return the index of the object if found, -1 otherwise.
*/publicstatic <T> int find(T[] array, T object) {
for (int i = 0; i < array.length; i++) {
if (array[i].equals(object)) {
return i;
}
}
return -1;
}
}