可以用Collections.addAll(list,a)
或者list = Arrays.asList(a)
方法将一个数组转换成List
public class Test { public static void main(String[] args) { // int[] a = {1,2,3}; //基本类型的数组不行,会报错 Integer[] a = new Integer[]{1,2,3}; List<Integer> list = new ArrayList<>(); // Collections.addAll(list,a); list = Arrays.asList(a); System.out.println(list); } }
输出
[1, 2, 3]