Generate Infinite Stream of Double in Java Last Updated : 11 Dec, 2018 Comments Improve Suggest changes Like Article Like Report Given the task is to generate an infinite sequential unordered stream of double in Java. This can be done in following ways: Using DoubleStream.iterate(): Using the DoubleStream.iterate() method, iterate the DoubleStream with i by incrementing the value with 1. Print the DoubleStream with the help of forEach() method. Java import java.util.stream.*; public class GFG { // Main method public static void main(String[] args) { DoubleStream // Iterate the DoubleStream with i // by incrementing the value with 1 .iterate(0, i -> i + 1) // Print the DoubleStream // using forEach() method. .forEach(System.out::println); } } Output: 0.0 1.0 2.0 3.0 4.0 5.0 6.0 . . . Using Random.doubles(): Get the next double using doubles() method Print the DoubleStream with the help of forEach() method. Java import java.util.stream.*; import java.util.*; public class GFG { // Main method public static void main(String[] args) { // Create a Random object Random random = new Random(); random // Get the next double // using doubles() method .doubles() // Print the DoubleStream // using forEach() method. .forEach(System.out::println); } } Output: 0.3668625445505631 0.4385898887922953 0.23333911864591927 0.7134958163360963 0.6945667694181287 0.6898427735417596 0.9243923588584183 . . . Using DoubleStream.generate() method: Generate the next double using DoubleStream.generate() and Random.nextDouble() Print the DoubleStream with the help of forEach() method. Java import java.util.stream.*; import java.util.*; public class GFG { // Main method public static void main(String[] args) { // Create a Random object Random random = new Random(); DoubleStream // Generate the next double // using DoubleStream.generate() // and Random.nextDouble() .generate(random::nextDouble) // Print the DoubleStream // using forEach() method. .forEach(System.out::println); } } Output: 0.025801080723973246 0.5115037630832635 0.030815898624858784 0.5441584143944648 0.6984267528746901 0.5821292304544626 . . . Comment More infoAdvertise with us Next Article Stream generate() method in Java with examples R RishabhPrabhu Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Generate Infinite Stream of Integers in Java Given the task is to generate an infinite sequential unordered stream of integers in Java. This can be done in following ways: Using IntStream.iterate(): Using the IntStream.iterate() method, iterate the IntStream with i by incrementing the value with 1. Print the IntStream with the help of forEach( 2 min read Stream generate() method in Java with examples Stream generate(Supplier<T> s) returns an infinite sequential unordered stream where each element is generated by the provided Supplier. This is suitable for generating constant streams, streams of random elements, etc. Syntax : static <T> Stream<T> generate(Supplier<T> s) Wh 1 min read IntStream generate() method in Java In Java, the IntStream.generate() method is part of the java.util.stream.IntStream class. This method is used to generate an infinite sequential and unordered stream of int values. This method takes IntSupplier as an argument. Note: It is commonly used for generating random numbers, constant streams 3 min read Integer doubleValue() Method in Java The doubleValue() method of Integer class of java.lang package is used to convert the value of the given Integer to a Double type after a widening primitive conversion and returns it. Syntax: public double doubleValue() Parameters: The method does not take any parameter. Return Value: This method re 1 min read DoubleAdder intValue() method in Java with Examples The java.DoubleAdder.intValue() is an inbuilt method in java that returns the sum() as an int after a narrowing primitive conversion. When the object of the class is created its initial value is zero. Syntax: public int intValue() Parameters: This method does not accepts any parameter. Return Value: 1 min read PrintStream print(double) method in Java with Examples The print(double) method of PrintStream Class in Java is used to print the specified double value on the stream. This double value is taken as a parameter. Syntax: public void print(double doubleValue) Parameters: This method accepts a mandatory parameter doubleValue which is the double value to be 2 min read Like