DoubleStream parallel() method in Java


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

Updated on: 30-Jul-2019

74 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements