LongStream parallel() method in Java

Java 8Object Oriented ProgrammingProgramming

<p>The parallel() method of the LongStream class in Java returns an equivalent stream that is parallel.</p><p>The syntax is as follows:</p><pre class="prettyprint notranslate">LongStream parallel()</pre><p>To use the LongStream class in Java, import the following package</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/O9mdVw" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate">import java.util.stream.LongStream;</pre><p>The following is an example to implement LongStream parallel() method in Java:</p><pre class="prettyprint notranslate">import java.util.stream.LongStream; public class Demo { &nbsp; &nbsp;public static void main(String[] args) { &nbsp; &nbsp; &nbsp; LongStream longStream = LongStream.range(10L, 20L); &nbsp; &nbsp; &nbsp; System.out.println(&quot;Parallel LongStream = &quot;); &nbsp; &nbsp; &nbsp; longStream.parallel().forEach(System.out::println); &nbsp; &nbsp;} }</pre><h2>output</h2><pre class="result notranslate">Parallel LongStream = 16 15 10 17 11 13 12 19 18 14</pre>
raja
Updated on 30-Jul-2019 22:30:25

Advertisements