I just append two string array into one array list and then convert it to string array to pass return variable as string[]
public static void main(String[] args) {
String [] a = {"america", "bakrain", "canada"};
String [] b = {"denmark", "europe" };
try{
List<String> listString = new ArrayList<String>(Arrays.asList(a));
listString.addAll(Arrays.asList(b));
String [] outResult= (String[])listString.toArray();
System.out.println(outResult);
} catch (Exception e) {
e.printStackTrace();
}
}
the error comes
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
at myFirst.myClass.main(myClass.java:26)
How to solve this issue?