字符数组和List的互相转化

//字符数组转List
String[] s = {"a","b","c"};
List list= java.util.Arrays.asList(s);

//List转字符数组——例子一
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);   
}  


//List转字符数组——例子二
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);   
     }  


//List转字符数组——例子三
List<String> list = new ArrayList<String>();   
list.add("a1");   
list.add("a2");   
           
String[] toBeStored = new String[]{};   
String[] str = al.toArray(toBeStored);   
for (String s : str) {   
              System.out.println(s);   
}  



利用此转化:String str[] = list.toArray(new String[]{});  

          List   list= java.util.Arrays.asList(String str[]);

你可能感兴趣的:(java,C++,c,C#)