Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 哈希集编译错误_Java_Compiler Errors_Hashset - Fatal编程技术网

Java 哈希集编译错误

Java 哈希集编译错误,java,compiler-errors,hashset,Java,Compiler Errors,Hashset,我想做的唯一一件事是将数组(temp_X)放入哈希集中,但我得到了哈希集的错误:没有为哈希集(List)找到合适的构造函数 public psresidualreducation(intxdisc[]],double[]]pat_cand,intk){ for(int i=0;i

我想做的唯一一件事是将数组(temp_X)放入哈希集中,但我得到了哈希集的错误:没有为哈希集(List)找到合适的构造函数

public psresidualreducation(intxdisc[]],double[]]pat_cand,intk){
for(int i=0;i
知道如何修复它吗?

接受一个类型数组,这意味着使用的所有元素都必须是
对象
类型,而不是原语

改用
整数
数组:

Integer[] temp_X;
这将允许使用
数组#asList
来针对包装器类:

HashSet<Integer> temp_XList = new HashSet<Integer>(Arrays.asList(temp_X));
HashSet temp_XList=新的HashSet(Arrays.asList(temp_X));

数组中的
temp_X
必须是对象数组,而不是基元类型数组。而且
HashSet
不支持基元类型。您必须将temp\u X中的每个int转换为
Integer
,并逐个添加到temp\u xList中

@Vahid Reimeus并不是建议您不使用
HashSet
。他建议您将
temp\ux
int[]
更改为
Integer[]
。或者将
temp\u X
更改为
列表。是的,您是对的。我以前没有完全阅读解决方案。
HashSet<Integer> temp_XList = new HashSet<Integer>(Arrays.asList(temp_X));