Question
Consider the following Java code snippet: Â Â
import java.util.PriorityQueue;   import java.util.Comparator;   class Item {     int priority;     String name;     public Item(int priority, String name) {       this.priority = priority;       this.name = name;     }     @Override     public String toString() {       return name + "(" + priority + ")";     }   }   public class HeapQuestion7 {     public static void main(String[] args) {       // Create a min-heap based on 'priority'       PriorityQueue pq = new PriorityQueue(Comparator.comparingInt(item -> item.priority));       pq.add(new Item(5, "Task A"));       pq.add(new Item(1, "Task B"));       pq.add(new Item(10, "Task C"));       pq.add(new Item(3, "Task D"));       System.out.println(pq.poll().name);       System.out.println(pq.poll().name);     }   }   What will be the output of this program?Solution
The PriorityQueue is initialized with a Comparator that orders Item objects based on their priority field in ascending order (min-heap behavior for priority).   1. pq.add(new Item(5, "Task A"));   2. pq.add(new Item(1, "Task B"));   3. pq.add(new Item(10, "Task C"));   4. pq.add(new Item(3, "Task D"));     After these additions, the item with the lowest priority value will be at the head of the queue. The priorities are 1, 3, 5, 10.   5. System.out.println(pq.poll().name);     The item with priority 1 ("Task B") is removed and its name is printed.   6. System.out.println(pq.poll().name);     The next item with the lowest priority (from the remaining items) is the one with priority 3 ("Task D"). It is removed and its name is printed.   Therefore, the output is Task B, Task D.
The Indecent Representation of Women (Prohibition) Act. 1986. is published in the Gazette of India on:-
Which of the following correctly explains the constitutional consequences when a local law (a Panchayat Act) conflicts with a State law on a subject in ...
Which of the following is prohibited under the Foreign Exchange Management Act (FEMA), 1999?
Agreement is defined in Section _____ of the Indian Contract Act, 1872.
The case Badruddin Rukonddim Karpude v. State of Maharashtra relates to_____.
What is the time limit for a person to apply to the High Court to set aside a declaration of forfeiture under Section 96 of CrPC?
Under the Insolvency and Bankruptcy Code, 2016, which authority is primarily responsible for overseeing the corporate insolvency resolution process?
What is the primary duty of the Board of Approval under Section 9(1) of the SEZ Act?
Importation of a girl or boy from a foreign country for illicit intercourse under Section 141 applies if:Â
Under the Companies Act, 2013, "Key Managerial Personnel" (KMP) does NOT include:Â