Java 給 List 賦值的方法有以下幾種:
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
Integer[] array = {1, 2, 3};
List<Integer> list = Arrays.asList(array);
List<Integer> list = new ArrayList<>();
Set<Integer> set = new HashSet<>();
set.add(1);
set.add(2);
set.add(3);
Collections.addAll(list, set.toArray(new Integer[0]));
List<Integer> list = Stream.of(1, 2, 3).collect(Collectors.toList());
List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3));