我想通过该方法float
为 a 添加一个值。但是,我收到此错误...float
ArrayList
.add()
no suitable method found for add(double)
method java.util.ArrayList.add(int,java.lang.Float) is not applicable
(actual and formal argument lists differ in length)
method java.util.ArrayList.add(java.lang.Float) is not applicable
(actual argument double cannot be converted to java.lang.Float by method invocation conversion)
这是我的代码...
class Exercise {
public static void main(String[] args) {
ArrayList<Float> floatList = new ArrayList<Float>();
floatList.add(10.0);
floatList.add(15.5);
floatList.add(18.0);
floatList.add(29.5);
floatList.add(45.5);
for(Float num : floatList){
System.out.println("\n"+ num);
}
}
}
有人可以帮我解决这个问题。