LongStream iterator()返回此流的元素的迭代器。这是终端操作,即可能会遍历流以产生结果或副作用。
用法:
PrimitiveIterator.OfLong iterator() Where, PrimitiveIterator.OfLong is an Iterator specialized for long values.
返回值:LongStream iterator()返回此流的元素迭代器。
示例1:
// Java code for LongStream iterator()
import java.util.*;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an LongStream
LongStream stream = LongStream.of(2L, 4L, 6L, 8L);
// Using LongStream iterator() to return
// an iterator for elements of the stream
PrimitiveIterator.OfLong answer = stream.iterator();
// Displaying the stream elements
while (answer.hasNext()) {
System.out.println(answer.nextLong());
}
}
}
输出:
2 4 6 8
示例2:
// Java code for LongStream iterator()
import java.util.*;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an LongStream which includes
// lower bound element but excludes
// upper bound element
LongStream stream = LongStream.range(2L, 8L);
// Using LongStream iterator() to return
// an iterator for elements of the stream
PrimitiveIterator.OfLong answer = stream.iterator();
// Displaying the stream elements
while (answer.hasNext()) {
System.out.println(answer.nextLong());
}
}
}
输出:
2 3 4 5 6 7
相关用法
- Java LongStream of()用法及代码示例
- Java LongStream sum()用法及代码示例
- Java LongStream findFirst()用法及代码示例
- Java LongStream mapToObj()用法及代码示例
- Java LongStream max()用法及代码示例
- Java LongStream min()用法及代码示例
- Java LongStream range()用法及代码示例
- Java LongStream concat()用法及代码示例
- Java LongStream sequential()用法及代码示例
- Java LongStream rangeClosed()用法及代码示例
- Java LongStream parallel()用法及代码示例
- Java LongStream skip()用法及代码示例
- Java LongStream sorted()用法及代码示例
- Java LongStream summaryStatistics()用法及代码示例
- Java LongStream mapToDouble()用法及代码示例
注:本文由纯净天空筛选整理自Sahil_Bansall大神的英文原创作品 LongStream iterator() in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。