Answer to Question #272510 in Java | JSP | JSF for @@@@@@@@@@

Question #272510

riorityQueue class which is implemented in the collection framework provides us a way to process the objects based on the priority. It is known that a queue follows First-In-First-Out algorithm, but sometimes the elements of the queue are needed to be processed according to the priority, that’s when the PriorityQueue comes into play. Let’s see how to create a queue object using this class.


1
Expert's answer
2021-11-28T05:26:57-0500


import java.util.*;
import java.io.*;


public class Main {


	public static void main(String args[])
	{
		PriorityQueue<Integer> pq = new PriorityQueue<>();


		pq.add(10);
		pq.add(20);
		pq.add(30);
		pq.add(40);
		pq.add(50);


		System.out.println("Initial PriorityQueue:\n" + pq);


		pq.remove(50);


		System.out.println("After Remove:\n" + pq);
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS