java range 字母,Java IntStream range()用法及代碼示例

IntStream range(int startInclusive,int endExclusive)以1為增量步長從startInclusive(包括)到endExclusive(不包括)返回順序的有序IntStream。

用法:

static IntStream range(int startInclusive, int endExclusive)

參數:

IntStream :原始整數值元素的序列。

startInclusive :包含的初始值。

endExclusive :專屬上限。

返回值:一個int元素範圍的順序IntStream。

例:

// Implementation of IntStream range

// (int startInclusive, int endExclusive)

import java.util.*;

import java.util.stream.IntStream;

class GFG {

// Driver code

public static void main(String[] args)

{

// Creating an IntStream

IntStream stream = IntStream.range(6, 10);

// Displaying the elements in range

// including the lower bound but

// excluding the upper bound

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

}

}

輸出:

6

7

8

9

注意:IntStream範圍(int startInclusive,int endExclusive)本質上像for循環一樣工作。可以依次產生一個等效的遞增值序列,如下所示:

for (int i = startInclusive; i < endExclusive ; i++)

{

...

...

...

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值