字串陣列轉換為ArrayList集合
阿新 • • 發佈:2019-01-25
ArrayList<String> strs = new ArrayList<String>(); System.out.println(strs.size()); String[] newitems = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L" }; List<String> items = Arrays.asList(newitems); ArrayList<String> aitems = new ArrayList<String>(items);
List<String> list=new ArrayList<String>(); list.add("王利虎"); list.add("張三"); list.add("李四"); int size=list.size(); String[] array = (String[])list.toArray(new String[size]); for(int i=0;i<array.length;i++){ System.out.print(array[i]); } for(String str:aitems) { System.out.print(str); }