java中的range方法_Java中的IntStream range()方法

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:27   1979   0

range()Java中IntStream类中的方法用于以1的增量步从startInclusive到endExclusive返回顺序的有序IntStream。这也包括startInclusive。

语法如下-static IntStream range(int startInclusive, int endExclusive)

在这里,参数startInclusive包含起始值,而endExclusive不包含最后一个值

要使用Java中的IntStream类,请导入以下包-import java.util.stream.IntStream;

创建一个IntStream并使用range()方法在一个范围内添加流元素。这将在范围内以1的增量步长返回顺序的有序IntStream-intStream.forEach(System.out::println);

以下是range()在Java中实现IntStream方法的示例-

示例import java.util.*;

import java.util.stream.IntStream;

public class Demo {

public static void main(String[] args) {

IntStream intStream = IntStream.range(20, 30);

intStream.forEach(System.out::println);

}

}

输出结果20

21

22

23

24

25

26

27

28

29

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP