list与数组转换

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]);

 
上一篇:JS字符串操作大全


下一篇:Knockout.js 初探