Integer[] spam = new Integer[] { 1, 2, 3 }; List<Integer> rlt = Arrays.asList(spam);
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