Converting ArrayList
Attempting to convert an ArrayList
To successfully perform this conversion, the correct approach is to create a new String[] array of the same size as the ArrayList
Code Example:
List<String> stockList = new ArrayList<String>(); stockList.add("stock1"); stockList.add("stock2"); String[] stockArr = new String[stockList.size()]; stockArr = stockList.toArray(stockArr); for(String s : stockArr) System.out.println(s);
Output:
stock1 stock2
By following this approach, you can successfully convert an ArrayList
The above is the detailed content of How to Properly Convert an ArrayList to a String[] Array in Java?. For more information, please follow other related articles on the PHP Chinese website!