List集合与int[]数组之间的转换

字符串和list的转化非常方便,如下:
String[] strArray = { “array-a”, “array-b” };
List strList = new ArrayList<>(strArray.length);

int型这么做就会报错:error: no suitable method found for toArray(int[])

必须通过赋值来转化,实例如下:
List list=new ArrayList();
int [] arr = new int[list.size()];
for(int k=0;k<arr.length;k++)
{
arr[k]=list.get(k);
}
return arr;

发布了117 篇原创文章 · 获赞 10 · 访问量 3176

猜你喜欢

转载自blog.csdn.net/weixin_43484977/article/details/104999957
今日推荐