How to convert an ArrayList containing Integers to primitive int array?

public static int[] convertIntegers(List integers)
    int[] ret = new int[integers.size()];
    for (int i=0; i < ret.length; i++)
        ret[i] = integers.get(i).intValue();
    return ret;

Google Guava:

List list = ...;
int[] values = Ints.toArray(list);

Leave a Reply

Your email address will not be published. Required fields are marked *