Java 中的集合不能直接存储原始值。
它们只能存储实例/对象。
使用 IntStream
的 boxed()
方法,我们可以获得可以通过 Collectors
方法收集的包装对象流。
List<Integer> ints = IntStream.of(1,2,3,4,5) .boxed() .collect(Collectors.toList()); System.out.println(ints);
输出:
[1, 2, 3, 4, 5]
日期:2020-09-17 00:09:31 来源:oir作者:oir