Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { public static <C> boolean containsElementOfType(final Collection<?> pList, final Class<C> pType) { return getElementsOfType(pList, pType).size() > 0; } /** * Gets the elements of received type within the received list. * * @param pList * the list * @param pType * the type to search for * * @return the elements of the received type */ @SuppressWarnings("unchecked") public static <C> List<C> getElementsOfType(final Collection<?> pList, final Class<C> pType) { final List<C> list = new ArrayList<C>(); if (pList != null && pList.size() > 0) { synchronized (pList) { for (final Object obj : pList) { if (pType.isAssignableFrom(obj.getClass())) { list.add((C) obj); } } } } return list; } }