Questions
3–4 questions per semester paper
Difficulty
Medium
Importance
High yield for University theory and practical lab exams
Overview
The Java Collections Framework is a unified architecture for storing and manipulating groups of objects. It is a critical topic in university computer science exams as it tests your ability to choose the most efficient data structure for specific programming requirements.
List, Set, and Map Interfaces
These are the three primary interfaces of the Collection hierarchy, each serving a specific storage purpose. Understanding their underlying implementation classes like ArrayList, HashSet, and HashMap is essential for writing efficient Java code.
- List allows duplicate elements and maintains insertion order
- Set prohibits duplicate elements and is unordered in HashSet
- Map stores data in key-value pairs with unique keys
- ArrayList uses a dynamic array for fast retrieval
- LinkedList provides efficient insertion and deletion
- TreeMap implements NavigableMap and keeps keys sorted
Iterators and Fail-Fast Behavior
The Iterator interface provides a standardized way to traverse elements in a collection without exposing the underlying structure. Modern Java exams focus on how Iterators handle structural modifications during traversal.
- Iterator supports hasNext() and next() methods
- ListIterator extends Iterator to support bidirectional traversal
- Fail-fast iterators throw ConcurrentModificationException if structure is modified
- Enhanced for-loop is syntactic sugar for Iterator
- Iterator can remove elements safely during iteration
Comparable vs Comparator
These interfaces are used to define the natural or custom ordering of objects in collections. Distinguishing between their implementation logic is a frequent viva and written exam question.
- Comparable uses compareTo() for natural ordering
- Comparator uses compare() for custom ordering
- Comparable modifies the original class (implements interface)
- Comparator is external to the class being sorted
- Collections.sort() supports both interfaces
Formula Sheet
Collections.sort(list)
Collections.sort(list, comparator)
public int compareTo(T o)
public int compare(T o1, T o2)
Exam Tip
Always link your answer to the internal data structure used (e.g., hash table, array, or binary tree) to demonstrate technical depth.
Common Mistakes
- Confusing the order and uniqueness properties of ArrayList, HashSet, and LinkedHashSet.
- Attempting to modify a collection while iterating over it using a for-each loop.
- Misremembering that Map is not technically a child of the Collection interface.
More Revision Notes
Ready to test yourself?
Play topic-wise Collections Framework questions in Aspirant Arcade — gamified MCQ practice.
Download Free