Home java java.lang.arraystoreException

java.lang.arraystoreException

Author

Date

Category

I have an array of type Object and you need to remake it in an array String .

I do it like this:

public static string [] convertorobjectToString (Object [] Objarr)
{
  String [] Strarr = Arrays.Copyof (Objarr, Objarr.Length, String []. Class);
  Return Strarr;
}

But I get a mistake:

java.lang.arraystoreException

What’s wrong?


Answer 1, Authority 100%

Error says that the source array is not all consisting of string.

can be done more reliable:

string [] Strarr = New String [Objarr.Length]
For (int i = 0; I & LT; Objarr.Length; I ++) {
 STRARR [I] = STRING.VALUEOF (OBJARR [I]);
}

Answer 2, Authority 25%

And so it is impossible. If you in the source array are stored Object and their actual type is not string, then they cannot be put into the string array [].
You can of course call the source array at the TOSTRING () method as @andrew Bystrov.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions