DoubleStream sequential() in Java

DoubleStream sequential() returns a sequential DoubleStream. It may return itself, either because the stream was already sequential, or because the underlying stream state was modified to be sequential.

DoubleStream sequential() is an intermediate operation. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output.

Syntax :



DoubleStream sequential()

Where, DoubleStream is a sequence of primitive
double-valued element.

Return Value : A sequential DoubleStream.
Example 1 : DoubleStream sequential() to return a sequential DoubleStream.

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code for DoubleStream sequential()
// to return a sequential DoubleStream.
import java.util.*;
import java.util.stream.DoubleStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an DoubleStream
        DoubleStream stream = DoubleStream.of(3.3, 5.4, 9.2,
                                              12.1, 14.4);
  
        // Using DoubleStream sequential()
        DoubleStream streamNew = stream.sequential();
  
        // Displaying sequential DoubleStream
        streamNew.forEach(System.out::println);
    }
}

chevron_right


Output:

3.3
5.4
9.2
12.1
14.4

Example 2 : DoubleStream sequential() on empty DoubleStream.

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code for DoubleStream sequential()
// on empty DoubleStream
import java.util.*;
import java.util.stream.DoubleStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an empty DoubleStream
        DoubleStream stream = DoubleStream.empty();
  
        // To check if it is parallel or not
        System.out.println("parallel : " + stream.isParallel());
  
        stream = stream.parallel();
  
        // To check if it is parallel or not
        System.out.println("parallel : " + stream.isParallel());
  
        stream = stream.sequential();
  
        // To check if it is parallel or not
        System.out.println("parallel : " + stream.isParallel());
    }
}

chevron_right


Output:

parallel : false
parallel : true
parallel : false


My Personal Notes arrow_drop_up

In love with a semicolon because sometimes i miss it so badly)

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.