Well, I would prefer to use the List
interface, that way you can swap the List
implementation out without changing caller code. Also, you could use the diamond operator. Finally, you could construct the new ArrayList
with an optimal initial capacity -
List<Game> gameList = getAllGames();
List<String> stringList = new ArrayList<>(gameList.size());
for (Game game : gameList) {
stringList.add(game.toString());
}
Or a new helper method like,
public static List<String> getStringList(List<?> in) {
List<String> al = new ArrayList<>(in != null ? in.size() : 0);
for (Object obj : in) {
al.add(obj.toString());
}
return al;
}
then
List<String> stringList = getStringList(gameList);