Other than looping through each element in an array and setting each one to null, is there a native function in Java / processing to simply empty an array (or destroy it, to
I was able to do that with the following 2 lines, I had an array called selected_items used to get all selected items on a dataTable
selected_items = null;
selected_items = [];
Faster clearing than Arrays.fill is with this (From Fast Serialization Lib). I just use arrayCopy (is native) to clear the array:
static Object[] EmptyObjArray = new Object[10000];
public static void clear(Object[] arr) {
final int arrlen = arr.length;
clear(arr, arrlen);
}
public static void clear(Object[] arr, int arrlen) {
int count = 0;
final int length = EmptyObjArray.length;
while( arrlen - count > length) {
System.arraycopy(EmptyObjArray,0,arr,count, length);
count += length;
}
System.arraycopy(EmptyObjArray,0,arr,count, arrlen -count);
}