Java中的IntStream range()方法
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
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短