Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { /** * Modifies and returns the collection. */ public static Collection filterByClass(Collection collection, Class c) { for (Iterator i = collection.iterator(); i.hasNext();) { Object item = i.next(); if (!c.isInstance(item)) { i.remove(); } } return collection; } }