我正在尝试将一些 Comparable 元素放入集合中并将其作为 Comparable[] 返回。
public Comparable[] getPerms() {
ArrayList<Comparable> resList = new ArrayList<Comparable>();
while(hasNext()) {
for (int i=0; i<r; i++) {
resList.add(index[i]);
}
moveIndex();
}
Comparable[] resultArray ;//how convert resList into array
return resultArray;
}
但是,我不知道如何获取 ArrayList<Comparable>
作为Comparable[]
感谢任何帮助。
最佳答案
resList.toArray(new Comparable[resList.size()])
关于java - 将 java ArrayList<Comparable> 转换为 Comparable[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15241606/