使用 Arrays.stream(),需要“装箱”一下:
1 int[] arr2 = {234, 2, 23, 777, 2}; 2 List<Integer> list2 = Arrays.stream(arr2).boxed().collect(Collectors.toList());
对于 Integer 数组,可以使用 Arrays.stream、Collections.addAll 或者 Stream.of 进行转换:
1 Integer[] arr2 = {234, 2, 23, 777, 2}; 2 3 List<Integer> list = new ArrayList<>(arr2.length); 4 Collections.addAll(list, arr2); 5 6 List<Integer> list1 = Stream.of(arr2).collect(Collectors.toList()); 7 8 List<Integer> list2 = Arrays.stream(arr2).collect(Collectors.toList());
参考:
https://blog.csdn.net/ASDQWE09876/article/details/79271992
原文:https://www.cnblogs.com/ainsliaea/p/11366481.html