I have a list of integers, List and I'd like to convert all the integer objects into Strings, thus finishing up with a new List.
Naturally, I could create a new List and loop through the list calling String.valueOf() for each integer, but I was wondering if there was a better (read: more automatic) way of doing it?
解决方案
As far as I know, iterate and instantiate is the only way to do this. Something like (for others potential help, since I'm sure you know how to do this):
List oldList = ...
/* Specify the size of the list up front to prevent resizing. */
List newList = new ArrayList(oldList.size())
for (Integer myInt : oldList) {
newList.add(String.valueOf(myInt));
}