Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { @SuppressWarnings("unchecked") public static <O> List<O> convert(List<?> list, Class<O> clazz) { if (list == null) { return null; } List<O> converted = new ArrayList<O>(); for (Object item : list) { if (clazz.isInstance(item)) { converted.add((O) item); } } return converted; } }