-3

I am writing this using JAVA. I am putting objects into my vehicleList array and I am having issues returning the array in my getVehicleList class. My vehicleList is an array of Vehicle[]. I keep getting "String cannot be converted to String[]. I hope I am making some sense. Here is my UseTaxList class. Any help would be much appreciated. Thank you.

This is what I have so far and I keep getting the error "String cannot be converted to String[]". I know what the error means, but I don't know how to resolve it.

public Vehicle[] getVehicleList() {

  String[] result;
  for (int i = 0; i < vehicleList.length; i++) {
     result += vehicleList[i].toString();
  }

  return result;

}

1 Answers1

0

If you simply want to convert all Elements from the vehicleList to String-Objects, you can write

String[] result = new String[vehicleList.length];
for (int i = 0; i < vehicleList.length; i++)
    result[i] = vehicleList[i].toString();

return result;

Simply write the code into your getVehicleList()-Method. You might have to add a custom toString()-Method in your Vehicle-Class!

WhiteBr0wnie_24
  • 149
  • 1
  • 1
  • 12
  • 1
    I would recommend to clarify your question, narrow down the scope and limit the amount of code to the only essential part. Also, please specify the language/framework. Best regards, – Alexander Bell Dec 06 '14 at 01:41
  • yes please do so, because it is pretty unclear what you exactly want. if you want a fast and precise answer, your question should also be short and only contain the code, that is necessary to describe your question. – WhiteBr0wnie_24 Dec 06 '14 at 01:43
  • @Charlie2004 You might want to try my answer, it should work (if vehicleList is an array, which it should be, if you are using vehicleList.length. – WhiteBr0wnie_24 Dec 06 '14 at 01:52
  • WhiteBro0wnie. Thank you for the response. I am trying your suggestion now. – Charlie2004 Dec 06 '14 at 02:00