PRACTICE • LEARN • GROW
Module 10: Collections Framework - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 10: Collections Framework - Final Quiz Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
Which core collection interface in the Java Collections Framework does NOT extend the root
Collection interface?
A.
List
B.
Set
C.
Map
D.
Queue
Explanation & Key
Correct Answer:
2
What is the primary performance trade-off between
ArrayList and LinkedList for get-by-index operations?
A.
ArrayList is O(1) random access via contiguous array indexing; LinkedList is O(N) sequential traversal through node pointers
B.
LinkedList is O(1); ArrayList is O(N)
C.
Both are O(1) on modern 64-bit processors
D.
Both are O(log N) using binary search
Explanation & Key
Correct Answer:
3
How does
HashSet guarantee that no duplicate elements are stored?
A.
By sorting all elements into an array after each insertion
B.
By utilizing an internal HashMap where inserted elements serve as keys, relying on their
hashCode() and equals() implementations
C.
By using synchronized locks on memory addresses
D.
By converting all objects to strings
Explanation & Key
Correct Answer:
4
What underlying data structure does
TreeSet use to keep its elements sorted in logarithmic O(log N) time?
A.
Dynamic resizable array
B.
Self-balancing Red-Black Tree (via TreeMap)
C.
Doubly linked list with skip pointers
D.
Min-heap priority queue
Explanation & Key
Correct Answer:
5
How does
HashMap locate the bucket slot for a key when executing get(key) or put(key, value)?
A.
By scanning all array elements from index 0 sequentially
B.
By invoking the key's
hashCode() method and computing an array index modulo bucket array length
C.
By executing a binary search on sorted keys
D.
By consulting the JVM operating system registry
Explanation & Key
Correct Answer:
6
What is printed by this Map update code?
Map map = new HashMap<>();
map.put("Java", 8);
map.put("Java", 17);
System.out.println(map.get("Java"));
A.
8
B.
17
C.
25
D.
null
Explanation & Key
Correct Answer:
7
Which interface should you select when you need to maintain a FIFO (First-In, First-Out) processing order of tasks?
A.
List
B.
Queue
C.
Set
D.
Map
Explanation & Key
Correct Answer:
8
What will happen when attempting to remove an element during enhanced for-loop iteration?
List list = new ArrayList<>(Arrays.asList("A", "B", "C"));
for (String s : list) {
if (s.equals("B")) {
list.remove(s);
}
}
A.
Successfully removes 'B' and finishes without errors
B.
Throws ConcurrentModificationException at runtime
C.
Removes 'A' instead of 'B'
D.
Enters an infinite loop
Explanation & Key
Correct Answer:
9
In Java 8+, at what threshold does a bucket linked list in a
HashMap convert into a balanced Red-Black Tree (Treeification)?
A.
When bucket count exceeds 16
B.
When a single bucket's collision chain reaches 8 elements (and total table capacity is at least 64)
C.
When total map size exceeds 10,000 entries
D.
Only when load factor reaches 1.0
Explanation & Key
Correct Answer:
10
What will be the output if a mutable key in a HashMap has its fields modified after being inserted?
class Key {
int id;
Key(int id) { this.id = id; }
public int hashCode() { return id; }
public boolean equals(Object o) { return (o instanceof Key) && ((Key)o).id == this.id; }
}
Key k = new Key(1);
Map map = new HashMap<>();
map.put(k, "Alpha");
k.id = 2; // Mutating key after insertion!
System.out.println(map.get(k));
A.
Alpha
B.
null
C.
Throws NullPointerException
D.
Throws ConcurrentModificationException
Explanation & Key
Correct Answer:
11
What is the key difference between the
Comparable and Comparator interfaces in Java?
A.
Comparable is in java.lang and defines natural ordering via compareTo(); Comparator is in java.util and defines custom external orderings via compare()
B.
Comparable is for numbers; Comparator is for Strings
C.
Comparable sorts in descending order; Comparator sorts in ascending order
D.
Comparable cannot be used with Collections.sort()
Explanation & Key
Correct Answer:
12
What happens when executing list.add() on a List created by Arrays.asList()?
List list = Arrays.asList(1, 2, 3);
list.add(4);
A.
Appends 4 successfully and resizes the list
B.
Throws java.lang.UnsupportedOperationException at runtime
C.
Throws ArrayStoreException
D.
Silently ignores the element
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong