How to convert the Object[] to String[] in Java? -
i have question java. have object[]
(java default, not user-defined) , want convert string[]
. can me? thank you.
this conversion
for(int = 0 ; < objectarr.length ; ++){ try { strarr[i] = objectarr[i].tostring(); } catch (nullpointerexception ex) { // default initialization } }
this casting
string [] strarr = (string[]) objectarr; //this give class cast exception
update:
tweak 1
string[] stringarray = arrays.copyof(objectarray, objectarray.length, string[].class);
tweak2
arrays.aslist(object_array).toarray(new string[object_array.length]);
note:that works if objects strings; current code works if not
fortweak1 :only on java 1.6 , above
Comments
Post a Comment