parallelStream(): This method is available in java.util.PriorityQueue class of Java.
Syntax:
Stream<K> java.util.Collection.parallelStream()
This method returns a possibly parallel Stream with this collection as its source.
Parameters: NA
Returns: a possibly parallel Stream over the elements in this collection.
Exceptions: NA
Approach
Java
import java.util.PriorityQueue;import java.util.stream.Stream;public class PriorityQueueparallelStream {public static void main(String[] args) {PriorityQueue<Integer> priorityQueue =new PriorityQueue<Integer>();priorityQueue.add(12);priorityQueue.add(5);priorityQueue.add(10);priorityQueue.add(2);Stream<Integer> stream = priorityQueue.parallelStream();System.out.println(stream.count());}}
Output:
4
No comments:
Post a Comment