Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

How I can convert ArrayList<String> to String[]? I'm tried to use this code:

ArrayList<String> al = getResources()...; //getting string-array from values.xml
String[] data = new String[al.size()];

for (int i = 0; i != al.size(); i++) {
    data[i] = al.get(i);
}

But it's very slow. How I can do it faster?

share|improve this question

marked as duplicate by Dariusz, Juvanis, Lajos Veres, Alex K, Niels Keurentjes Dec 21 '13 at 2:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers 3

up vote 8 down vote accepted

(String[]) al.toArray(); will do the trick.

share|improve this answer
    
Ejjectly.. Fast and Correct. –  Prince Dec 20 '13 at 13:03
    
Wow... so many answers for that short time! –  SuperCreeper Dec 20 '13 at 13:07

Use ArrayList.toArray() method to convert list of string to array of string.

Do like this

String[] data = al.toArray(new String[al.size()]);
share|improve this answer

Try this:

arraylist.toArray(array); // fill the array

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.