
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
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