Java tutorial
//package com.java2s; //License from project: Apache License import java.util.Collections; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; public class Main { public static <T, R> List<R> map(List<T> list, Function<T, R> fun) { return list.stream().map(fun::apply).collect(Collectors.toList()); } public static List<?> toList(Object obj) { if (obj instanceof List) { return (List<?>) obj; } else if (obj == null) { return Collections.emptyList(); } else { return Collections.singletonList(obj); } } }