Object Object_Array[]=new Object[100];
String String_Array[]=new String[Object_Array.length];
for (int i=0;i<String_Array.length;i++) String_Array[i]=Object_Array[i].toString();
Code to convert an object array to a String array. String_Array=(String[])Object_Array;
I was thinking about another way, but a runtime error occurred
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
Isn't there a way to do it that way?
string java array
There is a way to write System.arraycopy
.
String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class);
© 2024 OneMinuteCode. All rights reserved.