用于 int 范围的 Java 8 IntStream?

2022-01-22 00:00:00 lambda java-8 java java-stream

有没有办法为一系列整数创建一个 IntStream?

Is there a way to create an IntStream for a range of ints?

如果我想流式传输值 1 到 1000,我可以调用一些 IntStream 静态工厂来流式传输该范围?

Like if I wanted to stream values 1 to 1000, I could invoke some IntStream static factory to stream that range?

IntStream.forRange(1, 1000).forEach(//do something...

推荐答案

算了,看了好几遍都不知道为什么API文档里漏掉了……

Never mind, I don't know why I missed it in the API documentation after reading it several times...

IntStream.range(1,1000)

相关文章