I have a simple array that I declare below but getting incompatible types error, when trying to pass values from another class. Also, is there a better way of declaring the array below instead of saying initialize to 10 positions?
我有一个简单的数组,我在下面声明但是在尝试从另一个类传递值时会出现不兼容的类型错误。另外,有没有更好的方法来声明下面的数组而不是说初始化为10个位置?
float[] myarray = new float[10];
for(StudentClass score:total){
myarray = ((float)score.getRiskValue()); //incompatible types here
}
1 个解决方案
#1
1
Instead of foreach use for loop
而不是foreach用于循环
ArrayList<StudentClass> score = new ArrayList<>();//initialize the list with data here
float[] myarray = new float[score.size()];
for(int i=0;i<score.size();i++){
myarray[i] = ((float)score.getRiskValue());
}
#1
1
Instead of foreach use for loop
而不是foreach用于循环
ArrayList<StudentClass> score = new ArrayList<>();//initialize the list with data here
float[] myarray = new float[score.size()];
for(int i=0;i<score.size();i++){
myarray[i] = ((float)score.getRiskValue());
}