Java Utililty Methods List Cast

List of utility methods to do List Cast

Description

The list of methods to do List Cast are organized into topic(s).

Method

ListcastList(Class clazz, Collection c)
This method verifies the content of a list.
List<T> r = new ArrayList<T>(c.size());
for (Object o : c)
    r.add(clazz.cast(o));
return r;
ListcastList(Class clazz, Collection c)
cast List
List<T> r = new ArrayList<T>(c.size());
for (Object o : c)
    r.add(clazz.cast(o));
return r;
ListcastList(Class clazz, Collection collection)
Casts a raw Collection to a generic List .
List<T> genericList = new ArrayList<T>(collection.size());
for (Object object : collection) {
    genericList.add(clazz.cast(object));
return genericList;
ListcastList(Class elementType, List list)
cast List
if (list == null) {
    return null;
for (Object element : list) {
    if (!elementType.isAssignableFrom(element.getClass())) {
        throw new Exception("List element has invalid type -- expected '" + elementType.getName()
                + "', got: " + element.getClass().getName());
return (List<T>) list;
ListcastList(Class klass, List list)
cast List
return castList(klass, list, false);
ListcastList(Collection c)
INTERNAL: Cast collection as list or make a new list.
if (c instanceof List)
    return (List<T>) c;
else
    return new ArrayList<T>(c);
ListcastList(final List original)
Convert a list of type List to List if the cast is acceptable for all elements of the input list.
List<T> result = new ArrayList<T>();
for (E record : original)
    result.add((T) record);
return Collections.unmodifiableList(result);
ListcastList(final Object object)
Cast Object to List .
return (List<T>) object;
ListcastList(List list, Class clazz)
Casts a list containing elements of class T to a list containing elements of a subclass E.
return (List<E>) list;
ListcastListElem(List list, V target)
Creates a new list of the objects cast as the type passed as target.
List<V> result = new ArrayList<V>(list.size());
for (T elem : list) {
    result.add((V) elem);
return result;