Java Streams - DoubleStream iterate(double seed, DoubleUnaryOperator f) example








DoubleStream iterate(double seed, DoubleUnaryOperator f) returns an infinite sequential ordered DoubleStream produced by applying f to an initial element seed, producing a Stream consisting of seed, f(seed), f(f(seed)), etc.

Syntax

iterate has the following syntax.

static DoubleStream iterate(double seed,   DoubleUnaryOperator f)

Example

The following example shows how to use iterate.

import java.util.stream.DoubleStream;

public class Main {
  public static void main(String[] args) {
    DoubleStream i = DoubleStream.iterate(1.2,d->d*d);
    i.limit(3).forEach(System.out::println);
  }
}

The code above generates the following result.