如何将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;
}
Run Code Online (Sandbox Code Playgroud)
我在Intvalue.add上遇到错误(Integer.valueOf(value [i]),null);
请帮我
谢谢
java 5添加了autoboxing,所以你应该能够使用它
int i=3;
Integer number=i;//number now equals 3
Run Code Online (Sandbox Code Playgroud)
您收到错误的原因是因为您使用数组作为索引并尝试在此索引处添加null.如果你的数组是{100,101,102},它会尝试在索引100,101和102的intValues中添加null,它们不存在,给你IndexOutOfBoundsEception;
| 归档时间: |
|
| 查看次数: |
28156 次 |
| 最近记录: |