【发布时间】:2015-10-22 04:13:09
【问题描述】:
有谁知道如何将双数组列表传递给另一个方法? (我已突出显示)我从编译器收到此消息:cannot convert from ArrayList to double[]
ArrayList<Double> value = new ArrayList<Double>();
while (rs.next())
{
ArrayList<Integer> r=new ArrayList<Integer>();
r.add(rs.getInt("Type"));
r.add(rs.getInt("Budget"));
r.add(rs.getInt("Day"));
r.add(rs.getInt("Preferences"));
int vec2[] = r.stream().mapToInt(t -> t).toArray();
double cos_sim=cosine_similarity(vec1,vec2);
value.add(cos_sim);
}
pick_highest_value_here_and_display(value);
ps.close();
rs.close();
conn.close();
}
private void pick_highest_value_here_and_display(ArrayList<Double> value) {
// TODO Auto-generated method stub
**double aa[]=value ;**
double highest=aa[0];
for(int i=0;i<aa.length;i++)
{
if(aa[i]>highest){
highest=aa[i];
}
}
System.out.println(highest);
}
【问题讨论】:
-
@Jashaszun 的 double 方法与 int 相同吗?
-
除了可能重复的事实,正如某人已经说过的那样,您为什么要使其成为数组?您也可以通过索引获取 ArrayList 的元素,也可以通过索引修改它们。
-
你的
pick_highest_value_here_and_display方法可以简单地是double maxValue = Collections.max(...);