Here you can find the source of createSubList(Collection> source, Class
public static <T> List<T> createSubList(Collection<?> source, Class<T> type)
//package com.java2s; /******************************************************************************* * * Copyright (c) 2004-2011 Oracle Corporation. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: /*from ww w.jav a 2 s .c om*/ * * Kohsuke Kawaguchi, Winston Prakash * * *******************************************************************************/ import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /** * Create a sub-list by only picking up instances of the specified type. */ public static <T> List<T> createSubList(Collection<?> source, Class<T> type) { List<T> r = new ArrayList<T>(); for (Object item : source) { if (type.isInstance(item)) { r.add(type.cast(item)); } } return r; } }