What is the Java Collections Framework?
The Java Collections Framework is a set of ready made classes and interfaces for storing groups of objects. The main types are List for ordered items that allow duplicates, Set for unique items, and Map for key and value pairs. Common implementations include ArrayList, HashSet, and HashMap. It saves you from writing your own data structures.
- The Collections Framework is a set of ready made data structures and algorithms in Java.
- Core interfaces are List, Set, Queue, and Map, each with several implementations.
- It saves you from writing common structures like dynamic arrays and hash maps yourself.
The main interfaces
- List: ordered, allows duplicates, access by index. Example: ArrayList, LinkedList.
- Set: no duplicates, order depends on the type. Example: HashSet, TreeSet.
- Map: stores key to value pairs, keys are unique. Example: HashMap, TreeMap.
- Queue: holds items for processing in an order. Example: LinkedList, PriorityQueue.
List<String> names = new ArrayList<>();
Set<Integer> ids = new HashSet<>();
Map<String,Integer> ages = new HashMap<>();
Interviewers often ask which collection you would use for a scenario. Practice quick picks: ArrayList for indexed access, HashSet for uniqueness, HashMap for key lookups. Matching the structure to the need is the real skill here.
Frequently asked questions
What is the difference between a List and a Set?
A List keeps insertion order and allows duplicates, while a Set stores only unique elements and may not keep order, depending on the implementation.
Is Map part of the Collection interface?
No. Map is part of the framework but does not extend the Collection interface, because it stores key and value pairs rather than single elements.
Common follow up questions
Related interview questions
Want the full Java guide?
Read every Java concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the Java guide All Java questions