Close

Java 8 Streams - DoubleStream.iterate Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.DoubleStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.DoubleStreamDoubleStreamLogicBig

Method:

static DoubleStream iterate(double seed,
                            DoubleUnaryOperator f)

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

Examples


package com.logicbig.example.doublestream;

import java.util.stream.DoubleStream;

public class IterateExample {

public static void main(String... args) {
DoubleStream.iterate(1, d -> d + 0.5)
.limit(5)
.forEach(System.out::println);
}
}

Output

1.0
1.5
2.0
2.5
3.0




See Also