how to use IntStream.rangeclose in java ?
时间: 2024-05-09 20:15:43 浏览: 13
`IntStream.rangeClosed` is a method in Java that returns a sequential ordered `IntStream` from `startInclusive` to `endInclusive` by an incremental step of one.
Here's an example of how to use `IntStream.rangeClosed` in Java:
```java
import java.util.stream.IntStream;
public class IntStreamExample {
public static void main(String[] args) {
// Create an IntStream from 1 to 10 (inclusive)
IntStream.rangeClosed(1, 10)
.forEach(System.out::println);
}
}
```
The output of the above code will be:
```
1
2
3
4
5
6
7
8
9
10
```
In the above example, we created an `IntStream` from 1 to 10 (inclusive) using the `IntStream.rangeClosed` method and then used the `forEach` method to print each element of the stream.