这是我的方法,它有两个带有arrayList的参数
private static PriorityInfo getPrioritiesInfo(ArrayList priorityNumber ,ArrayList priorityDate) {
PriorityInfo priorityInfo = new PriorityInfo();
ArrayList temp = new ArrayList();
for(int i=0;i<priorityNumber.size();i++){
priorityInfo.setPriorityNo(toString(priorityNumber.get(i)));
}
//priorityInfo.setPriorityDate(priorityDate);
return priorityInfo;
}
我的期望:
上述方法产生错误
method toString in class Object cannot be applied to given types;
required: no arguments
found: Object
reason: actual and formal argument lists differ in length
setPriorityNo方法来自PriorityInfo.class:
public void setPriorityNo(String priorityNo) {
this.priorityNo = priorityNo;
}
让我知道我的错误
答案 0 :(得分:2)
您没有正确转换为字符串。你指的是Object类中的toString方法。
尝试这样的事情:
private static PriorityInfo getPrioritiesInfo(ArrayList priorityNumber, ArrayList priorityDate) {
PriorityInfo priorityInfo = new PriorityInfo(new ArrayList());
ArrayList temp = new ArrayList();
for(int i=0;i<priorityNumber.size();i++){
priorityInfo.setPriorityNumbers(priorityNumber.get(i).toString());
}
//priorityInfo.setPriorityDate(priorityDate);
return priorityInfo;
}
在你传递的ArrayList priorityNumber上调用.toString()方法。
和您的PriorityInfo类:
class PriorityInfo {
private ArrayList priorityNumbers;
public PriorityInfo(ArrayList priorityNumbers) {
this.priorityNumbers = priorityNumbers;
}
public void setPriorityNumbers(String priorityNo) {
this.priorityNumbers.add(priorityNo);
}
public ArrayList getPriorityNumbers() {
return this.priorityNumbers;
}
}
不知道您在PriorityInfo类中有哪些其他方法。
答案 1 :(得分:0)
我正在使用带有StringUtils的Apache Commons库
private static PriorityInfo getPrioritiesInfo(ArrayList priorityNumber ,ArrayList priorityDate) {
PriorityInfo priorityInfo = new PriorityInfo();
String temp="";
for (int i = 0; i < priorityNumber.size(); i++) {
String value = StringUtils.join(priorityNumber.get(i), '|');
temp = temp.concat(value);
}
priorityInfo.setPriorityNo(temp);
return priorityInfo;
}