Here are 10 essential multiple-choice questions on Java Queue and Map Interface, covering key concepts.
Question 2
What is the time complexity of offer(), poll(), and peek() operations in PriorityQueue?
Question 3
What will be the output of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
Queue<Integer> queue = new PriorityQueue<>();
queue.add(30);
queue.add(10);
queue.add(50);
queue.add(20);
System.out.println(queue.poll());
}
}
Question 6
What will be the output of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<>();
map.put("A", 10);
map.put("B", 20);
map.put("A", 30);
System.out.println(map.get("A"));
}
}
Question 8
What will be the output of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
Map<Integer, String> map = new LinkedHashMap<>();
map.put(3, "Three");
map.put(1, "One");
map.put(2, "Two");
System.out.println(map.keySet());
}
}
Question 10
What will be the output of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<>();
map.put("X", 100);
map.put("Y", 200);
map.put(null, 300);
System.out.println(map.get(null));
}
}
There are 10 questions to complete.
Quiz about Java Queue and Map Interface