Here are 10 essential multiple-choice questions on Java Collection Framework, covering key concepts
Question 1
Which of the following is NOT a part of the Java Collection Framework?
Map
Queue
Array
Set
Question 2
What will be the output of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("A"); list.add("B"); list.add("C");
Collections.reverse(list);
System.out.println(list);
}
}
[A, B, C]
[C, B, A]
Compilation Error
Runtime Error
Question 3
Which interface extends Collection but does NOT allow duplicate elements?
List
Queue
Set
Map
Question 4
Which method in the Collections class is used to make a collection immutable?
Collections.lock()
Collections.unmodifiableCollection()
Collections.freeze()
Collections.readOnlyCollection()
Question 5
What will happen if you try to add a null key in a HashMap?
Throws NullPointerException
Allowed only if the value is non-null
Allowed, but only once
Allowed multiple times
Question 6
Which of the following is true about LinkedHashSet?
It allows duplicate elements
It maintains insertion order
It sorts elements in ascending order
It does not use hashing
Question 7
What is the default capacity of ArrayList when using the no-arg constructor?
0
10
16
1
Question 8
What will be the output of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(1, 2, 3, 4);
Collections.fill(list, 5);
System.out.println(list);
}
}
[1, 2, 3, 4]
[5, 5, 5, 5]
Compilation Error
Runtime Error
Question 9
Which of the following Queue implementations provides thread-safe access?
LinkedList
PriorityQueue
ArrayDeque
ConcurrentLinkedQueue
Question 10
What is the key difference between Collection and Collections?
Collection is a class, while Collections is an interface
Collection is an interface, while Collections is a utility class
Both are interfaces
Both are utility classes
There are 10 questions to complete.