Java List Create createSubList(Collection source, Class type)

Here you can find the source of createSubList(Collection source, Class type)

Description

Create a sub-list by only picking up instances of the specified type.

License

Open Source License

Declaration

public static <T> List<T> createSubList(Collection<?> source, Class<T> type) 

Method Source Code

//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;
    }
}

Related

  1. createStringFromIntegerList(List lst)
  2. CreateStringList(Collection values)
  3. createStringList(String csvString)
  4. createStringList(String spaceDelimitedString)
  5. createStringListFromStringArr(String[] stringArr)
  6. createSublist(final T[] elements, final Class listImplementation)
  7. createSymbolNameString_From_Parts(List descTagName_Parts)
  8. createTable(List datas, String[] headers, int numColumns, int cellPadding, int border)
  9. createTagList(List tags, String separator)