Question
Consider the following Java code snippet: Â Â
import java.util.PriorityQueue; Â Â public class HeapQuestion5 { Â Â Â Â public static void main(String[] args) { Â Â Â Â Â Â PriorityQueue pq = new PriorityQueue(); Â Â Â Â Â Â pq.add("apple"); Â Â Â Â Â Â pq.add("banana"); Â Â Â Â Â Â pq.add("cherry"); Â Â Â Â Â Â System.out.println(pq.peek()); Â Â Â Â Â Â System.out.println(pq.size()); Â Â Â Â Â Â System.out.println(pq.peek()); Â Â Â Â } Â Â } Â Â What will be the output of this program?Solution
PriorityQueue for String uses natural ordering (alphabetical) by default, making it a min-heap.   1. pq.add("apple"); pq.add("banana"); pq.add("cherry");     The elements are added. "apple" is the smallest alphabetically.   2. System.out.println(pq.peek());     peek() retrieves the head of the queue (the highest-priority element) *without removing it*. So, "apple" is printed.   3. System.out.println(pq.size());     The size of the queue is still 3, as peek() does not remove elements. So, 3 is printed.   4. System.out.println(pq.peek());     Again, peek() retrieves the head without removal. "apple" is still the head. So, "apple" is printed.   Therefore, the output is apple, 3, apple.
In the question, assuming the given statements to be true, find which of the conclusion (s) among given three conclusions is /are definitely true and t...
In the question, assuming the given statements to be true, find which of the conclusion (s) among given three conclusions is /are definitely true and t...
Statements: Z % Y; X # W; U % V; W & V; Y @ X
Conclusions:Â Â Â Â Â
I. U @ X Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ...
Statements: Â Y $ Z, H $ D, Z * D
Conclusions: Â Â Â Â a) Y & HÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â b) Y * D
...In the question, assuming the given statements to be true, find which of the conclusion (s) among given three conclusions is /are definitely true and t...
In the question, assuming the given statements to be true, find which of the conclusion (s) among given two conclusions is /are definitely true and the...
Statements:
L ≥ M = N < P; O < Q ≥ R =S ≥ L
Conclusions:
I). Q > M
II). Q = N
Statement: F < G < H ≥ J; F ≥ K > L
Conclusion:
I. H > L
II. H = L
Statement: X > W = P; X > G > F; X < O
Conclusion: I. F < W      II. P ≤ F
Statements: J < K; L = M; K >N ≥ L
Conclusions:
I. J < L
II. N = M