java - Array Class Returns Address -
i using java , trying getvehiclelist method print out contents vehicle[] vehiclelist. however, when call getvehiclelist, returns lvehicle;@61443d8f
instead.
i think memory address if correct. not sure if relevant, here example of should print out. thank you.
jones, jo: car 2014 honda accord (alternative fuel) value: $22,000.00 use tax: $110.00 tax rate: 0.005 jones, sam: car 2014 honda accord value: $22,000.00 use tax: $220.00 tax rate: 0.01
here code returns memory address instead.
public vehicle[] getvehiclelist() { vehicle[] result = new vehicle[vehiclelist.length]; (int = 0; < vehiclelist.length; i++) { result[i] = vehiclelist[i]; } return result; }
this prints instead.
lvehicle;@61443d8f
here tostring()
public string tostring() { string result = ""; (int = 0; < vehiclelist.length; i++) { result += vehiclelist[i] + "\n\n"; } return result; }
you can implement
public string tostring(){ }
in vehicle class
since jvm not know how want present information inside vehicle class, have tell implementing tostring() method
Comments
Post a Comment