DoubleStream generate(DoubleSupplier s) example

Description

DoubleStream generate(DoubleSupplier s) returns an infinite sequential unordered stream generated by the provided DoubleSupplier.

Syntax

generate has the following syntax.


static DoubleStream generate(DoubleSupplier s)

Example

The following example shows how to use generate.


import java.util.Random;
import java.util.stream.DoubleStream;
import java.util.stream.Stream;
/*from w ww .  j  a v  a2s.  c  om*/
public class Main {
  public static void main(String[] args) {
    DoubleStream i = DoubleStream.generate(new Random()::nextDouble);
    Stream<Double> o =  i.boxed();
    
    o.limit(10).forEach(System.out::println);
  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder