Using Google Collections from Guava-Project, you could use the transform
method in the Lists class
import com.google.common.collect.Lists;
import com.google.common.base.Functions
List<Integer> integers = Arrays.asList(1, 2, 3, 4);
List<String> strings = Lists.transform(integers, Functions.toStringFunction());
The List
returned by transform
is a view on the backing list – the transformation will be applied on each access to the transformed list.
Be aware that Functions.toStringFunction()
will throw a NullPointerException
when applied to null, so only use it if you are sure your list will not contain null.