如何将Java 8 IntStream转换为List? [英] How do I convert a Java 8 IntStream to a List?
本文介绍了如何将Java 8 IntStream转换为List?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在查看 IntStream
的文档,我看到 toArray
方法,但没办法直接转到列表<整数>
I'm looking at the docs for the IntStream
, and I see an toArray
method, but no way to go directly to a List<Integer>
肯定有办法转换流
到列表
?
推荐答案
IntStream.boxed
将 IntStream
转换为 Stream< Integer>
,然后您可以收集
到列表中:
IntStream.boxed
turns an IntStream
into a Stream<Integer>
, which you can then collect
into a list:
theIntStream.boxed().collect(Collectors.toList())
这篇关于如何将Java 8 IntStream转换为List?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文