Java 类型ArrayList中的方法add(String)不适用于参数(String[])
我是JAVA和编程的初学者,所以请耐心等待,因为我可能没有使用正确的术语来正确描述我的疑问。不过,我会尽力的。 所以,我有一个ArrayList,我将在上面使用正则表达式,在逗号上拆分它。 我真的需要一些帮助来解决这个问题,即使我必须改变我做这个过程的方式。保持这种状态并不重要,对我来说最重要的是最终的结果。 多谢各位Java 类型ArrayList中的方法add(String)不适用于参数(String[]),java,arraylist,Java,Arraylist,我是JAVA和编程的初学者,所以请耐心等待,因为我可能没有使用正确的术语来正确描述我的疑问。不过,我会尽力的。 所以,我有一个ArrayList,我将在上面使用正则表达式,在逗号上拆分它。 我真的需要一些帮助来解决这个问题,即使我必须改变我做这个过程的方式。保持这种状态并不重要,对我来说最重要的是最终的结果。 多谢各位 String temp; String temp2; ArrayList <String> tempsplit = new ArrayList&
String temp;
String temp2;
ArrayList <String> tempsplit = new ArrayList<String> ();
ArrayList <String> dominios = new ArrayList<String> (); {
for (int h = 0; h < 191; h++){
temp = features.get(h);
**temp2.add(temp.split(","));
tempsplit.add(temp.split(","));**
//in these last couple lines I get the error "The method add(String) in the type ArrayList<String> is not applicable for the arguments (String[])"
for(int oi = 0; oi < tempsplit.size(); oi++){
for (int t = 0; t < dominios.size() ; t++){
int conf = 0;
if (tempsplit.get(oi) == dominios.get(t)){
conf = 0;
}
else{ conf = 1;
}
if (conf == 1){
dominios.add (tempsplit.get(oi));
}
}
}
您的Arraylist的类型为String而不是String[],您正在add中传递String数组,因为String.split将为您提供数组。您可以这样做
for(String a:temp.split(",")){
tempsplit.add(a);
}
您的Arraylist的类型为String而不是String[],您正在add中传递String数组,因为String.split将为您提供数组。您可以这样做
for(String a:temp.split(",")){
tempsplit.add(a);
}
类型ArrayList中的方法addString不适用于参数字符串[]
这意味着您有一个ArrayList,并且您正在尝试使用字符串数组String[]而不是单个字符串调用add方法。该方法需要单个字符串,而不是数组
Collections.addAll(temp2, temp.split(","));
类型ArrayList中的方法addString不适用于参数字符串[]
这意味着您有一个ArrayList,并且您正在尝试使用字符串数组String[]而不是单个字符串调用add方法。该方法需要单个字符串,而不是数组
Collections.addAll(temp2, temp.split(","));
这将使用帮助类集合按项添加字符串[]
这将使用帮助类集合按项添加字符串[]。temp.split,返回字符串[]
List.add将字符串作为参数,而不是字符串数组
但您可以使用,它将数组作为第二个参数:
Collections.addAll(temp2, temp.split(","));
您也可以从temp ArrayList使用addAllCollection c方法,但必须将数组转换为集合:
temp.split,返回字符串[]
List.add将字符串作为参数,而不是字符串数组
但您可以使用,它将数组作为第二个参数:
Collections.addAll(temp2, temp.split(","));
您也可以从temp ArrayList使用addAllCollection c方法,但必须将数组转换为集合:
问题代码基本上是:
ArrayList <String> tempsplit = new ArrayList<String>();
tempsplit.add(temp.split(",")); // compile error
或者使用实用程序addAll方法:
问题代码基本上是:
ArrayList <String> tempsplit = new ArrayList<String>();
tempsplit.add(temp.split(",")); // compile error
或者使用实用程序addAll方法:
你希望它能做什么?如果您希望它添加数组中的所有值,您可能希望addAll使用Arrays.asList包装数组……那么您希望它做什么?如果希望它添加数组中的所有值,则可能需要addAll使用Arrays.asList包装数组。。。