Close

Java 8 Streams - IntStream.iterate Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.IntStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.IntStreamIntStreamLogicBig

Method:

static IntStream iterate(int seed,
                         IntUnaryOperator f)

Returns an infinite sequential ordered IntStream produced by iterative application of the provided IntUnaryOperator. The seed is the initial element of the iteration.

Examples


package com.logicbig.example.intstream;

import java.util.stream.IntStream;

public class IterateExample {

public static void main(String... args) {
IntStream stream = IntStream.iterate(10, i -> i + 5)
.limit(5);
stream.forEach(System.out::println);
}
}

Output

10
15
20
25
30




See Also