This is similar to this question: http://stackoverflow.com/questions/880581/java-convert-int-to-integer
I'm new to Java. How can i convert a List to int[] in Java? I'm confused because List.toArray() actually returns an Object[], which can be cast to nether Integer[] or int[].
Right now I'm using a loop to do so:
int[] toIntArray(List<Integer> list){
int[] ret = new int[list.size()];
for(int i = 0;i < ret.length;i++)
ret[i] = list.get(i);
return ret;
}
I'm sure there's a better way to do this.