array to list
Integer[] spam = new Integer[] { 1, 2, 3 }; List<Integer> rlt = Arrays.asList(spam);
Object[] to list<T>
List<Object> objects = getObjects(); List<CustomClass> customObjects = myFilter(objects, CustomClass.class); static <E> List<E> myFilter(List<?> lst, Class<E> cls) { List<E> result = new ArrayList<E>(); for (Object obj : lst) { if (cls.isInstance(obj)) result.add(cls.cast(obj)); } return result; }
原文地址:https://www.cnblogs.com/codedreams/p/9954699.html
时间: 2024-11-02 16:53:13