Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.*; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Stream; import static java.util.stream.Collectors.toList; public class Main { public static <T> List<T> filterByType(Collection<? super T> objects, Class<T> type) { return objects.stream().filter(type::isInstance).map(type::cast).collect(toList()); } public static <A, B> List<B> map(Collection<? extends A> xs, Function<? super A, ? extends B> mapper) { return xs.stream().map(mapper).collect(toList()); } public static <A, B> List<B> map(A[] xs, Function<? super A, ? extends B> mapper) { return Stream.of(xs).map(mapper).collect(toList()); } public static <T> List<T> filter(Collection<? extends T> xs, Predicate<? super T> predicate) { return xs.stream().filter(predicate).collect(toList()); } }