Anto Anto - 1 year ago 76
Java Question

converting elements of a list to string

I would like to obtain the string text of the elements stored in a list, say

. Would the toArray() and the toString() methods be the best options?

Answer Source

Yes, but doing it manually gives you more control:

// initialize with the exact length
List<String> stringsList = new ArrayList<String>(listOfCard.size()); 
for (Car car : listOfCars) {

If you haven't overridden the toString() method and don't want to override id, you can use car.getName() isntead of car.toString() (or any property combination you like)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download