-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
  • 65,990
  • 13
  • 130
  • 167
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
  • 232,561
  • 37
  • 312
  • 386
0

Another way:

String[] result = new String[arrayList.size()];
arrayList.ToArray( result );
Captain Giraffe
  • 14,407
  • 6
  • 39
  • 67