Java examples for java.util:Collection Element
map each element in a collection via Function
import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.function.Function; public class Main{ public static <F, T> List<T> map(Collection<F> from, Function<F, T> func) { List<T> to = new ArrayList<T>(); for (F f : from) { func.apply(f);// ww w.j av a 2s .com } return to; } public static <F, T> List<T> map(F[] from, Function<F, T> func) { return map(Arrays.asList(from), func); } }