这个转换有什么问题?
public int getTheNumber(int[] factors) {
ArrayList<Integer> f = new ArrayList(Arrays.asList(factors));
Collections.sort(f);
return f.get(0)*f.get(f.size()-1);
}
在阅读Create ArrayList from array的解决方案后,我制作了这个程序。在getTheNumber(...)
函数的第二行(排序)中,会引起以下异常:
Exception in thread "main" java.lang.ClassCastException: [I cannot be cast to java.lang.Comparable]
出了什么问题?我知道可以使用Arrays.sort()
进行排序,但我对这种方式很感兴趣。