Close

Java 8 Streams - Stream.iterate Examples

[Last Updated: Nov 9, 2025]

Java 8 Streams Java Java API 


Interface:

java.util.stream.Stream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.StreamStreamLogicBig

Method:

static <T> Stream<T> iterate(T seed,
                             UnaryOperator<T> f)

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


Examples


package com.logicbig.example.stream;

import java.util.stream.Stream;

public class IterateExample {

public static void main(String... args) {
Stream<Integer> stream = Stream.iterate(0, i -> i + 1)
.limit(10);
stream.forEach(System.out::println);
}
}

Output

0
1
2
3
4
5
6
7
8
9




See Also

Join