Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting elements of a list to string

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?

like image 576
Anto Avatar asked Jan 23 '10 19:01

Anto


1 Answers

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.

like image 144
Adamski Avatar answered Oct 13 '22 00:10

Adamski