Convert ArrayList
In Android, converting an ArrayList
Problem:
Trying to convert an ArrayList
String [] stockArr = (String[]) stock_list.toArray();
results in an empty array.
Solution:
To correctly convert an ArrayList
Here's an example:
List<String> stockList = new ArrayList<String>(); stockList.add("stock1"); stockList.add("stock2"); String[] stockArr = new String[stockList.size()]; stockList.toArray(stockArr); for (String s : stockArr) { System.out.println(s); }
This code will output:
stock1 stock2
The above is the detailed content of How to Correctly Convert an ArrayList to a String[] Array in Android?. For more information, please follow other related articles on the PHP Chinese website!