IntStream iterator()返回此流的元素的迭代器。這是終端操作,即可能會遍曆流以產生結果或副作用。
用法:
PrimitiveIterator.OfInt iterator() Where, PrimitiveIterator.OfInt is an Iterator specialized for int values.
返回值:IntStream iterator()返回此流的元素迭代器。
示例1:
// Java code for IntStream iterator()
import java.util.*;
import java.util.stream.IntStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an IntStream
IntStream stream = IntStream.of(2, 4, 6, 8);
// Using IntStream iterator() to return
// an iterator for elements of the stream
PrimitiveIterator.OfInt answer = stream.iterator();
// Displaying the stream elements
while (answer.hasNext()) {
System.out.println(answer.nextInt());
}
}
}
輸出:
2 4 6 8
示例2:
// Java code for IntStream iterator()
import java.util.*;
import java.util.stream.IntStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an IntStream which includes
// lower bound element but excludes
// upper bound element
IntStream stream = IntStream.range(2, 8);
// Using IntStream iterator() to return
// an iterator for elements of the stream
PrimitiveIterator.OfInt answer = stream.iterator();
// Displaying the stream elements
while (answer.hasNext()) {
System.out.println(answer.nextInt());
}
}
}
輸出:
2 3 4 5 6 7
相關用法
- Java IntStream sum()用法及代碼示例
- Java IntStream of()用法及代碼示例
- Java IntStream findFirst()用法及代碼示例
- Java IntStream builder()用法及代碼示例
- Java IntStream boxed()用法及代碼示例
- Java IntStream parallel()用法及代碼示例
- Java IntStream mapToObj()用法及代碼示例
- Java IntStream sequential()用法及代碼示例
- Java IntStream range()用法及代碼示例
- Java IntStream sorted()用法及代碼示例
- Java IntStream asDoubleStream()用法及代碼示例
- Java IntStream rangeClosed()用法及代碼示例
- Java IntStream mapToDouble()用法及代碼示例
- Java IntStream limit()用法及代碼示例
- Java IntStream concat()用法及代碼示例
注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 IntStream iterator() in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。