I would like to obtain the string text of the elements stored in a list, say List<Car>
. Would the toArray() and the toString() methods be the best options?
Providing you don't object to the string output following the convention:
[A, B, C]
... you can simply call the List
'stoString()
method to obtain your output (I'm not sure why people are advocating using a loop for this). It may also be sensible to override Car's toString()
method to return a human-friendly description of the object.
However, if you wish to obtain each element as an individual String
you will need to iterate over the List one element at a time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With