Delete comment from: Java67
@jmzc: The object array objMnt is of type Object[] and contains String references, that's why you can downcast a reference in the array. You can store String references in an Object[] because the class String is derived from the class Object and therefore you can substitute objects of type String for objects with type Object.
The Object[] itself cannot be downcasted to String[] because String[] is a derived class of Object[]. This means even tough the Object[] object contains references to Strings, the Object[] object itself is _NOT_ a String[] object.
But back to the problem: You could also convert the ArrayList of strings in an easier way:
String[] strMnts = aListMonth.toArray( new String[aListMonth.size()] );
This method exists (AFAIK) because of the exact reason mentioned above. By passing in the pre-allocated array of type String[], the actual return type of toArray is of type String[] and not of type Object[].
Sep 22, 2012, 1:25:48 PM
Posted to How to convert an ArrayList to Array in Java? Example