1. Introduction
The Java Collections Framework (JCF) is a unified architecture for storing and manipulating groups of objects. It provides ready-made interfaces (List, Set, Queue, Map) and implementations (ArrayList, HashSet, HashMap, etc.) so you don't have to write your own data structures from scratch.
Cricket analogy: The ICC's standardized fielding positions (like slip, gully, mid-on) are ready-made roles a captain can assign instead of inventing new fielding names for every match, just as the Java Collections Framework offers ready-made List, Set, and Map structures.
Before collections, Java only had arrays (fixed size) and legacy classes like Vector and Hashtable. The JCF, introduced in Java 1.2, standardized how data is stored, traversed, and sorted, and made every implementation interchangeable through common interfaces.
Cricket analogy: Before helmets became standard equipment in the 1970s, batsmen used makeshift caps and improvised protection; the eventual standardized helmet rule made every player's gear interchangeable and safer, just as Java 1.2 standardized collections after ad-hoc arrays and Vector.
2. Syntax
// Collection hierarchy (interfaces)
Collection<E> --> List<E>, Set<E>, Queue<E>
Map<K, V> --> a SEPARATE hierarchy, NOT a subtype of Collection
// Common declarations
List<String> list = new ArrayList<>();
Set<String> set = new HashSet<>();
Map<String, Integer> map = new HashMap<>();
Queue<Integer> queue = new LinkedList<>();3. Explanation
At the top of the hierarchy sits the Collection interface, which is extended by List (ordered, allows duplicates), Set (no duplicates), and Queue (FIFO-style processing). Map is deliberately excluded from the Collection hierarchy because it stores key-value pairs rather than single elements — this is one of the most common exam and interview traps.
Cricket analogy: A cricket squad list allows duplicate skill sets (multiple all-rounders) like List, while the playing XI's unique batting order has no repeated players like Set; but the scoreboard, which pairs each player's name with runs like a Map, is a separate ledger, not part of the squad hierarchy.
Each interface has multiple implementations with different performance trade-offs: ArrayList vs LinkedList for List, HashSet vs TreeSet vs LinkedHashSet for Set, and HashMap vs TreeMap vs LinkedHashMap for Map. Choosing the right one depends on whether you need ordering, sorting, or fast random access.
Cricket analogy: Choosing between a fast opening batsman like Rohit Sharma (ArrayList, quick random access) and a patient anchor like Cheteshwar Pujara (LinkedList, efficient insertions) depends on match situation, just as picking ArrayList versus LinkedList depends on your access pattern.
Exam trap: Map does NOT extend Collection. If asked 'which of these interfaces extends Collection', Map is always the wrong answer alongside List, Set, and Queue.
4. Example
import java.util.*;
public class CollectionsDemo {
public static void main(String[] args) {
// List: ordered, duplicates allowed
List<String> fruits = new ArrayList<>();
fruits.add("Apple");
fruits.add("Banana");
fruits.add("Apple");
// Set: no duplicates
Set<String> uniqueFruits = new HashSet<>(fruits);
// Map: key-value pairs, not a Collection
Map<String, Integer> stock = new HashMap<>();
stock.put("Apple", 50);
stock.put("Banana", 30);
System.out.println("List: " + fruits);
System.out.println("Set size: " + uniqueFruits.size());
System.out.println("Map: " + stock);
}
}5. Output
List: [Apple, Banana, Apple]
Set size: 2
Map: {Apple=50, Banana=30}6. Key Takeaways
- Collection is the root interface for List, Set, and Queue.
- Map is a separate hierarchy and does NOT extend Collection.
- List preserves insertion order and allows duplicates; Set does not allow duplicates.
- Choosing an implementation (ArrayList vs LinkedList, HashMap vs TreeMap) depends on required ordering and performance.
- The framework was introduced in Java 1.2 to replace ad-hoc structures like Vector and Hashtable.
Practice what you learned
1. Which interface does Map extend in the Java Collections Framework?
2. Which of the following interfaces extends Collection?
3. In which Java version was the Collections Framework introduced?
4. Which legacy class predates the Collections Framework and is similar to ArrayList?
5. Which sub-interface of Collection allows duplicate elements while preserving insertion order?
Was this page helpful?
You May Also Like
ArrayList in Java
Learn how ArrayList works internally, its time complexity, and when to use it over arrays or LinkedList.
HashMap in Java
Learn how HashMap stores key-value pairs using hashing, its null-key rules, and why iteration order is not guaranteed.
Iterator in Java
Learn how to safely traverse and modify collections using Iterator, and why direct modification during a for-each loop throws ConcurrentModificationException.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics