码迷,mamicode.com
首页 > 编程语言 > 详细

list与数组转换

时间:2015-09-21 15:42:24      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

1、数组转换list
(1)
List myList = new ArrayList();
String[] myStringArray = new String[] {"Java", "is", "Cool"};
Collections.addAll(myList, myStringArray);
(2)
String[] words = { ... };
List<String> list = new ArrayList<String>(words.length);
for (String s : words) {
  list.add(s);
}
(3)
String[] words = {"ace", "boom", "crew", "dog", "eon"};
List<String> wordList = Arrays.asList(words);
2、list转换数组
List list = new ArrayList();
list.add("1");
list.add("2");
final int size = list.size();
String[] arr = (String[])list.toArray(new String[size]);

 

list与数组转换

标签:

原文地址:http://www.cnblogs.com/caroline4lc/p/4826101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!