數組和list互轉
阿新 • • 發佈:2017-10-12
.cn ring 數組 code size length slist color pre
數組轉list
方法1:
String[] stringArray = { "a", "b", "c", "d", "e" };
List<String> list = Arrays.asList(stringArray);
方法2:
ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(stringArray));
方法3:
List<String> list1 = new ArrayList<String>(stringArray.length); Collections.addAll(list1, stringArray);
list轉數組
List<String> list = new ArrayList<String>(); list.add("1"); list.add("2"); list.add("3"); String[] strings = new String[list.size()]; list.toArray(strings);
參考:http://www.cnblogs.com/liushaobo/p/4423102.html
數組和list互轉