- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DoubleStream generate() method in Java
The generate() method of the DoubleStream class 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, the parameter s is the DoubleSupplier for generated elements. The DoubleSupplier is 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 implement DoubleStream generate() method in Java
Example
import java.util.*; import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.generate(() -> { return (double)(Math.random() * 100); }); doubleStream.limit(5).forEach(System.out::println); } }
Output
66.39524427508303 3.184126437402224 18.562637999185117 19.340287633605 94.0690134411309
Advertisements