如何将 int 值转换为整数值?
这是我的代码-
private static int[] value= {R.drawable.collection1,R.drawable.collection2}
public static ArrayList<Integer> AddIntValue (int[] value){
ArrayList<Integer> Intvalue=new ArrayList<Integer>();
for(int i=0;i<value.length; i++)
{
Intvalue.add(Integer.valueOf(value[i]), null);
}
return Intvalue;
}
在 Intvalue.add(Integer.valueOf(value[i]), null); 上出现错误
请帮助我
谢谢
最佳答案
java 5 添加了自动装箱,因此您应该能够使用它
int i=3;
Integer number=i;//number now equals 3
您收到错误的原因是因为您正在使用数组作为索引并尝试在此索引处添加 null。如果您的数组是 {100,101,102},它会尝试将 null 添加到索引 100、101 和 102 处的 intValues(这些值不存在),从而给出 IndexOutOfBoundsEception;
关于java - 如何将 int 值赋给整型变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13430407/