Is there a way, to convert a List of Integers to Array of ints (not integer). Something like List to int []? Without looping through the list and manually converting the intger to int.
You can use the toArray
to get an array of Integers
, ArrayUtils
from the apache commons to convert it to an int[]
.
List<Integer> integerList = new ArrayList<Integer>();
Integer[] integerArray = integerList.toArray(new Integer[0]);
int[] intArray = ArrayUtils.toPrimitive(integerArray);
Resources :
ArrayUtils.toPrimitive(Integer[])
Collection.toArray(T[])
On the same topic :