LongStream parallel() method in Java

Java 8Object Oriented ProgrammingProgramming

The parallel() method of the LongStream class in Java returns an equivalent stream that is parallel.

The syntax is as follows:

LongStream parallel()

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

Example

 Live Demo

import java.util.stream.LongStream;

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

import java.util.stream.LongStream;
public class Demo {
   public static void main(String[] args) {
      LongStream longStream = LongStream.range(10L, 20L);
      System.out.println("Parallel LongStream = ");
      longStream.parallel().forEach(System.out::println);
   }
}

output

Parallel LongStream =
16
15
10
17
11
13
12
19
18
14
raja
Published on 28-Mar-2019 15:38:56
Advertisements