Java List Cast castList(Class clazz, Collection c)

Here you can find the source of castList(Class clazz, Collection c)

Description

This method verifies the content of a list.

License

Open Source License

Parameter

Parameter Description
clazz a parameter
c a parameter

Exception

Parameter Description
ClassCastException an exception

Declaration

public static <T> List<T> castList(Class<? extends T> clazz, Collection<?> c) throws ClassCastException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Main {
    /**/*from  ww w.  jav  a  2 s  .c  o  m*/
     * This method verifies the content of a list.
     * 
     * @param clazz
     * @param c
     * @return
     * @throws ClassCastException
     */
    public static <T> List<T> castList(Class<? extends T> clazz, Collection<?> c) throws ClassCastException {
        List<T> r = new ArrayList<T>(c.size());
        for (Object o : c)
            r.add(clazz.cast(o));
        return r;
    }
}

Related

  1. cast(List list)
  2. cast(List list, Class klass)
  3. cast(List from)
  4. CAST_LIST(Class className, Object obj)
  5. castList(Class clazz, Collection c)
  6. castList(Class clazz, Collection collection)
  7. castList(Class elementType, List list)
  8. castList(Class klass, List list)
  9. castList(Collection c)