List数组怎么转换成int[]数组?

「已注销」 2011-05-05 01:54:26
List数组怎么转换成int[]数组?

比如


List list = new ArrayList();
int suoyins[];

怎么把list中的值放入int数组中.怎么转换啊?
...全文
3473 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
杨大爷 2011-05-05
  • 打赏
  • 举报
回复
你引的包对么?
import java.util.List;
「已注销」 2011-05-05
  • 打赏
  • 举报
回复
算了,结贴.
getdate 2011-05-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 learshaw 的回复:]
List<Integer> list = new ArrayList<Integer>();
int[] a = new int[list.size()];
for(int i=0;i<list.size();i++)
{
a[i] = list.get(i);
}
[/Quote]

正解~
「已注销」 2011-05-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 learshaw 的回复:]
List<Integer> list = new ArrayList<Integer>();
int[] a = new int[list.size()];
for(int i=0;i<list.size();i++)
{
a[i] = list.get(i);
}
[/Quote]
我写了的转换不过来在Myeclipse中报错.下面显示红线编译都没通过啊.
「已注销」 2011-05-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 slabcde 的回复:]
使用List的如下方法<T> T[] toArray(T[] a)
[/Quote]
我写了的转换不过来在Myeclipse中报错.下面显示红线编译都没通过啊.
zhu6100441 2011-05-05
  • 打赏
  • 举报
回复
对不起,应该是size()方法。
zhu6100441 2011-05-05
  • 打赏
  • 举报
回复
int数组得先给定长度,就用list的length方法获得长度给int数组。
learshaw 2011-05-05
  • 打赏
  • 举报
回复
List<Integer> list = new ArrayList<Integer>();
int[] a = new int[list.size()];
for(int i=0;i<list.size();i++)
{
a[i] = list.get(i);
}
爱吃面条 2011-05-05
  • 打赏
  • 举报
回复
使用List的如下方法<T> T[] toArray(T[] a)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧