Arrays & Collections MCQs

Topic-wise practice questions for Programming (C++ / Java / Python). Test your knowledge, check solutions on demand, and pace your preparation.

Zero-leak answer engine • Rate-limited explanations
Practice in Timed Mode
Q1medium
Trace the output:

set = new HashSet();
set.add("A");
set.add("B");
set.add("A");
print(set.size());
Q2medium
Why is using an Array usually safer for performance-critical code than an ArrayList of Objects?
Q3easy
What is the output?

int[] arr = new int[3];
print(arr[0]);
(In a language like Java where arrays are zero-initialized)
Q4easy
Which data structure follows the LIFO (Last-In-First-Out) principle?
Q5medium
Trace the value of result:

Stack s = new Stack();
s.push(10);
s.push(20);
s.pop();
s.push(30);
result = s.peek();
Q6easy
What is the "Load Factor" of a HashMap?
Q7medium
In a 2D integer array matrix[5][10], how many total elements are stored in memory, and what is the index of the very last element?
Q8medium
You are given a list of 1 million student IDs, and you need to find all the unique IDs in the list. Which data structure is the most efficient choice for this task?
Q9medium
A developer needs to store pairs of "Country Name" and "Capital City." They need to be able to quickly find the capital given a country name. Which collection is best?
Q10hard
What is the Time Complexity of inserting a new element at the **index 0** of an ArrayList of size N?