2

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?

0

3 Answers 3

7

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

Sign up to request clarification or add additional context in comments.

2 Comments

Ejjectly.. Fast and Correct.
Wow... so many answers for that short time!
6

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

Do like this

String[] data = al.toArray(new String[al.size()]);

Comments

0

Try the following code:

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

Comments