1. 数组转换成列表
1.1 使用Arrays类的asList()方法
int[] array = new int[]{0, 1, 2, 3, 4};
List<Integer> list = Arrays.stream(array).boxed().collect(Collectors.toList());
1.2 使用new ArrayList<>()
String[] strings = new String[]{"0", "1", "2"};
List<String> stringList = new ArrayList<>(Arrays.asList(strings));
stringList.add("hello");
1.3 使用JDK8的Stream流操作
int[] ints = {1, 2, 3};
List<Integer> intList = Arrays.stream(ints).boxed().collect(Collectors.toList());
long[] longs = {1, 2, 3};
List<Long> longList = Arrays.stream(longs).boxed().collect(Collectors.toList());
double[] doubles = {1, 2, 3};
List<Double> doubleList = Arrays.stream(doubles).boxed().collect(Collectors.toList());
String[] strings = {"1", "2", "3"};
List<String> stringList = Arrays.stream(strings).collect(Collectors.toList());
引用类型与基础类型相比 少了 boxed 这一过程,是一个转包装类的过程。