###問題描述
將List<Integer>轉換成List<String>
###原來app
List<String> list = Lists.newArrayList(); for (Integer integer : source) { list.add(String.valueOf(integer)); }
###使用Guavacode
List<String> list = Lists.newArrayList(Iterables.transform(source, new Function<Integer, String>() { public String apply(Integer input) { return String.valueOf(input); } }));
或orm
list = Lists.newArrayList(Iterators.transform(source.iterator(), new Function<Integer, String>() { public String apply(Integer input) { return String.valueOf(input); } }));
或input
Lists中,Collections2中也有相似的transform方法