【Java】【1】String数组和List相互转换
正文:
1,String[]转List
String[] strs = {"aa", "bb", "cc"}; //String数组
//方法1
List<String> list1 = Arrays.asList(strs);
//方法2
List<String> list2 = new ArrayList<String>();
Collections.addAll(list2, strs);
//方法3
List<String> list3 = new ArrayList<String>();
for(String item : strs){
list3.add(item);
}
2,List转String[]
List<String> list = new ArrayList<>(); //list
list.add("a");
list.add("b");
list.add("c");
//方法1
String[] strs1 = list.toArray(new String[list.size()]);
//方法2
String[] strs2 = new String[list.size()];
for(int i=0; i<list.size(); i++){
strs2[i] = list.get(i);
}
参考博客:
1,java中String数组和List的互相转化 - qq_33157666的博客 - CSDN博客
https://blog.csdn.net/qq_33157666/article/details/77922945?locationNum=6&fps=1