How might I convert an ArrayList
object to a String[]
array in Java?
You can use Iterator
to iterate the elements of the ArrayList
:
ArrayList list = new ArrayList<>();
String[] array = new String[list.size()];
int i = 0;
for (Iterator iterator = list.iterator(); iterator.hasNext(); i++) {
array[i] = iterator.next();
}
Now you can retrive elements from String[]
using any Loop.