我唯一想做的就是将数组 (temp_X) 放入 HashSet,但我得到了 HashSet 的错误:没有找到适合 HashSet(List) 的构造函数
public PSResidualReduction(int Xdisc[][], double[][] pat_cand, int k) {
for (int i = 0; i < Xdisc.length; i++) {
int[] temp_X;
temp_X = new int[Xdisc[0].length];
for (int s = 0; s < Xdisc[0].length; s++) {
temp_X[s] = Xdisc[i][s];
}
HashSet<Integer> temp_XList = new HashSet<Integer>(Arrays.asList(temp_X));
}
}
知道如何修复它吗?
最佳答案
Arrays#asList接受类型数组,这意味着使用的所有元素都必须是 Object
类型而不是原始类型。
改用Integer
数组:
Integer[] temp_X;
这将允许使用 Arrays#asList
来对抗包装类:
HashSet<Integer> temp_XList = new HashSet<Integer>(Arrays.asList(temp_X));
关于java - HashSet 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16096412/