Q. What will be the output of the following code –
Code:
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
public class MyClass
{
public static void main(String args[])
{
PriorityQueue<Integer> q = new PriorityQueue<Integer>();
q.add(1);
q.add(2);
q.add(3);
System.out.println(q.poll());
System.out.println(q.offer(4));
q.add(1);
q.remove(2);
System.out.println(q.peek());
System.out.println(q);
}
}
β
Correct Answer: (A)
1 true 1 [1, 3, 4]