Home  >  Article  >  Java  >  Detailed explanation of several implementation methods for converting Java List into String array

Detailed explanation of several implementation methods for converting Java List into String array

高洛峰
高洛峰Original
2017-01-21 16:25:112430browse

Java List converted into String array

Implementation code:

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);
}

or

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);
}

Thanks for reading, I hope you can This helps everyone, thank you for your support of this site!

For more detailed explanations of several implementation methods for converting Java List into String array, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn