 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to generate Infinite Stream of Double in Java using DoubleStream.generate()
The DoubleStream.generate() method returns an infinite sequential unordered stream where each element is generated by the provided DoubleSupplier.
The syntax is as follows −
static DoubleStream generate(DoubleSupplier s)
Here, s is the DoubleSupplier for generated elements. The DoubleSupplier represents a supplier of double-valued results.
To use the DoubleStream class in Java, import the following package −
import java.util.stream.DoubleStream;
The following is an example to generate Infinite stream of Double in Java with DoubleStream.generate() method −
Example
import java.util.stream.*; import java.util.*; public class Demo {    public static void main(String[] args) {       Random r = new Random();       DoubleStream.generate(r::nextDouble).forEach(System.out::println);    } } Here is the output displaying an infinite stream of Double −
Output
0.387687687514162978 0.545465653820283890 0.17845763929620120 . . .
Advertisements
 