DoubleStream sequential() method in Java

Java 8Object Oriented ProgrammingProgramming

The sequential() method of the DoubleStream class returns an equivalent stream that is sequential.

The syntax is as follows

DoubleStream sequential()

To use the DoubleStream class in Java, import the following package

import java.util.stream.DoubleStream;

Create a DoubleStream and add some elements

DoubleStream doubleStream1 = DoubleStream.of(45.8, 67.9, 78.5, 90.6, 97.4);

Now create an equivalent stream that is sequential

DoubleStream doubleStream2 = doubleStream1.sequential();

The following is an example to implement DoubleStream sequential() method in Java

Example

 Live Demo

import java.util.*;
import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream1 = DoubleStream.of(45.8, 67.9, 78.5, 90.6, 97.4);
      DoubleStream doubleStream2 = doubleStream1.sequential();
      System.out.println("Equivalent new stream...");
      doubleStream2.forEach(System.out::println);
   }
}

Output

Equivalent new stream...
45.8
67.9
78.5
90.6
97.4
raja
Published on 28-Mar-2019 07:47:39

Advertisements