Java開發 小工具累計

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; }
相關文章
相關標籤/搜索