Update 3SumClosest

You can convert, but I don't think there's anything built in to do it automatically:




public static int[] convertIntegers(List<Integer> integers)
{
    int[] ret = new int[integers.size()];
    for (int i=0; i < ret.length; i++)
    {
        ret[i] = integers.get(i).intValue();
    }
    return ret;
}
(Note that this will throw a NullPointerException if either integers or any element within it is null.)




EDIT: As per comments, you may want to use the list iterator to avoid nasty costs with lists such as LinkedList:




public static int[] convertIntegers(List<Integer> integers)
{
    int[] ret = new int[integers.size()];
    Iterator<Integer> iterator = integers.iterator();
    for (int i = 0; i < ret.length; i++)
    {
        ret[i] = iterator.next().intValue();
    }
    return ret;
}
____________________________________________________________________
参照上面的ArrayList<Integer> 的method； 终于磕磕绊绊写出来了， 但是不是所有的测试都对，涉及到负数的时候， 相减绝对值会变大啊！！！ 怎么解决呢