Home / Programming MCQs / JAVA MCQs / Question

U

Uday Singh • 7.23K Points
Tutor III

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);
}
}
(A) 1 true 1 [1, 3, 4]
(B) 3 true 1 [1, 3, 4]
(C) 3 false 1 [1, 3, 4]
(D) 1 false 1 [1, 2, 4]

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.