package demo02; import java.util.ArrayList; import java.util.List; /** * @description: demo06 * @author: liuyang * @create: 2021-09-04 18:05 */ public class Demo06 { public static void main(String[] args) { Integer[] arr1 = {1, 2, 3, 4, 5}; List<Integer> list1 = copyArrayToList(arr1); System.out.println(list1); String[] arr2 = {"AA", "BB", "CC"}; List<String> list2 = copyArrayToList(arr2); System.out.println(list2); } /** * <E>用来指定E不是一个类型而是代表泛型 * @param arr * @param <E> * @return */ public static <E> List<E> copyArrayToList(E[] arr) { List<E> result = new ArrayList<>(); for (E e : arr) { result.add(e); } return result; } }