Java tutorial
//package com.java2s; import java.util.ArrayList; public class Main { /** * Filters Views based on the given class type. * * @param classToFilterBy the class to filter * @param viewList the Iterable to filter from * @return an ArrayList with filtered views */ public static <T> ArrayList<T> filterViews(Class<T> classToFilterBy, Iterable<?> viewList) { ArrayList<T> filteredViews = new ArrayList<T>(); for (Object view : viewList) { if (view != null && classToFilterBy.isAssignableFrom(view.getClass())) { filteredViews.add(classToFilterBy.cast(view)); } } viewList = null; return filteredViews; } }