
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.iterate()
The DoubleStream.iterate() returns an infinite sequential ordered DoubleStream produced by iterative application of a function f to an initial element seed, producing a Stream consisting of seed.
The syntax is as follows
static DoubleStream iterate(double seed, DoubleUnaryOperator f)
Here, seed is the initial element and f is a function to be applied to the previous element to produce a new element.
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.iterate()
Example
import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream.iterate(5, i -> i + 1).forEach(System.out::println); } }
Here is the output displaying infinite stream of Double
Output
5.0 6.0 7.0 . . .
Advertisements