Java List转换成String数组几种实现方式详解

时间:2022-09-22 21:40:35

Java List转换成String数组

实现代码:

?
1
2
3
4
5
6
7
List<String> list = new ArrayList<String>();
list.add("a1");
list.add("a2");
String[] toBeStored = list.toArray(new String[list.size()]);
for(String s : toBeStored) {
  System.out.println(s);
}

?
1
2
3
4
5
6
7
8
9
List<String> list = new ArrayList<String>();
list.add("a1");
list.add("a2");
   
String[] toBeStored = new String[al.size()];
list.toArray(toBeStored);
for (String s : toBeStored) {
  System.out.println(s);
}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!