I have a class called ArraySort which is generically typed
public class ArraySort<E> {
public void bubbleSort(E[] data) {...}
}
which takes in a type when initiating it
ArraySort<Integer> ArraySort = new ArraySort<Integer>();
This class supports different sorting algorithms as such, but whenever an array is inputted with null values in it
int[] arr = {3, 1, 5, null};
ArraySort.bubbleSort(arr);
My code errors out with a null pointer exception. I already tried to use a method from this thread, but this didn't work due to a 'java.lang.ArrayStoreException'.
public E[] clean(E[] v) {
ArrayList<E> list = new ArrayList<E>(Arrays.asList(v));
list.removeAll(Collections.singleton(null));
return (E[]) list.toArray(new String[list.size()]);
}
So my question is how do I remove all null values from a generically typed Array?