Say I have some lists:
List<Short> shortList;
List<Integer> integerList;
List<Long> longList;
List<Float> floatList;
List<Double> doubleList;
List<Boolean> booleanList;
And I want to convert them into their primitive equivalent:
short[] shortArray;
int[] intArray;
long[] longArray;
float[] floatArray;
double[] doubleArray;
boolean[] booleanArray;
I want to make a method to that accepts any type of List
of boxed primitives and return the equivalent array of unboxed primitives. I am not up to speed at Generics, so I took a shot and it doesn't work. This is what I have:
public static E[] convertObjectListToPrimitiveArray(List<T> list)
{
E[] primitiveArray = new E[list.size()];
int i=0;
for(T object : list){
E[i++] = object;
}
return primitiveArray;
}
What do I need to do to make this method work?