Java List Cast cast(Class clazz, List list)

Here you can find the source of cast(Class clazz, List list)

Description

cast

License

Apache License

Declaration

@SuppressWarnings("unchecked")
    public static <T> List<T> cast(Class<T> clazz, List<?> list) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> List<T> cast(Class<T> clazz, List<?> list) {

        ArrayList<T> castedList = new ArrayList<T>();

        for (Object o : list) {
            castedList.add((T) o);/*  w  ww.j av a  2s.  c om*/
        }

        return castedList;
    }
}

Related

  1. cast(final Class cls, final Object[] list)
  2. cast(final Collection list)
  3. cast(final List list)
  4. cast(List list)