DoubleStream parallel() method in Java

Java 8ProgrammingObject Oriented Programming

The parallel() method of the DoubleStream class returns an equivalent stream which is parallel.

The syntax is as follows

DoubleStream parallel()

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

import java.util.stream.DoubleStream;

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

Example

 Live Demo

import java.util.*;
import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(35.8, 14.9, 23.3, 67.8, 89.4, 45.6);
      System.out.println("Parallel DoubleStream = ");
      doubleStream.parallel().forEach(System.out::println);
   }
}

Output

Parallel DoubleStream =
67.8
14.9
23.3
89.4
45.6
35.8
raja
Published on 26-Mar-2019 14:37:04
Advertisements