-4

Possible Duplicate:
Convert a generic list to an array

So I am trying to convert the contents of my arraylist into an array. However I keep getting the error Type mismatch: cannot convert from Object[] to String or the error Type mismatch: cannot convert from String[] to String

any ideas how to solve this, I'm drawing up blanks. Thanks

Community
  • 1
  • 1

3 Answers3

0

Here is one way:

String[] listArr= new String[yourList.size()];
        Iterator<String> listIter = yourList.iterator();
        while (listIter .hasNext()) {
            listArr[count] = listIter .next();

        }

Note: There may be syntax errors, I just typed code here.

kosa
  • 64,776
  • 13
  • 121
  • 163
0

Try this:

String[] array = arrayList.toArray(new String[0]);

That is, assuming that the ArrayList was declared with type ArrayList<String>. Replace with the appropriate types if necessary.

Óscar López
  • 225,348
  • 35
  • 301
  • 374
0

Another way:

String[] result = new String[arrayList.size()];
arrayList.ToArray( result );
Captain Giraffe
  • 13,890
  • 5
  • 38
  • 65