Java tutorial
//package com.java2s; import java.util.*; public class Main { @SuppressWarnings("unchecked") public static <S, T> Collection<T> filter(Class<T> target, Collection<S> sourceCollection) { Collection<T> filtered = new ArrayList<T>(); for (S source : sourceCollection) if (source.getClass() == target) filtered.add((T) source); return filtered; } public static <S, T> Collection<T> filter(Class<T> target, S... sourceCollection) { Collection<T> filtered = new ArrayList<T>(); for (S source : sourceCollection) if (source.getClass() == target) filtered.add((T) source); return filtered; } }