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:
1.比较笨的方法
String[] words = { ... }; List<String> list = new ArrayList<String>(words.length); for (String s : words) { list.add(s); }
2.还可以的方法
import java.util.Collections; List myList = new ArrayList(); String[] myStringArray = new String[] {"Java", "is", "Cool"}; Collections.addAll(myList, myStringArray);
3.这个也行
List stooges = Arrays.asList("Larry", "Moe", "Curly");//返回的list不能执行add remove。 //可以用List list = new ArrayList(Arrays.asList(array));
String[] arr = new String[] {"1", "2"}; List list = Arrays.asList(arr);
参考:http://www.oschina.net/code/snippet_8676_2652
原文:http://my.oschina.net/itfanr/blog/348328