This repository contains the hands-on code examples used to teach the Java Collections Framework on the MK Code Club channel. Each lesson is a small, focused Java program that can be compiled and run independently, making it easy to follow along, experiment, and compare collection types.
The examples move from everyday list operations to sets, maps, stacks, queues, and useful helper methods from the Collections class.
- How to create, read, update, delete, and traverse collections
- The difference between ordered, sorted, and unordered collections
- How collections handle duplicate values
- How to store key-value pairs with maps
- How stack and queue data structures work
- How to use common methods from
java.util.Collections - How to choose a collection based on the behavior your program needs
| Lesson | File | Main topic | Concepts demonstrated |
|---|---|---|---|
| 1 | T1_ArrayList.java |
ArrayList | Add, read, update, remove, size, indexed traversal |
| 2 | T2_LinkedList.java |
LinkedList | Basic list operations plus first/last element methods |
| 3 | T3_HashSet.java |
HashSet | Unique values, remove, contains, size, clear |
| 4 | T4_LinkedHashSet.java |
LinkedHashSet | Unique values with insertion order preserved |
| 5 | T5_TreeSet.java |
TreeSet | Unique values maintained in sorted order |
| 6 | T6_HashMap.java |
HashMap | Key-value storage, lookup, key traversal, removal |
| 7 | T7_LinkedHashMap.java |
LinkedHashMap | Key-value storage with insertion order preserved |
| 8 | T8_TreeMap.java |
TreeMap | Key-value storage with keys kept sorted |
| 9 | T9_Stack.java |
Stack | LIFO behavior with push, pop, and peek |
| 10 | T10_Queue.java |
Queue | FIFO behavior with offer, poll, and peek |
| 11 | T11_Important_Methods.java |
Collections utilities | Sort, reverse sort, swap, frequency, min, max, binary search |
Lists keep elements in a sequence and allow duplicate values.
| Collection | Best known for | Ordering |
|---|---|---|
ArrayList |
Fast indexed access and general-purpose lists | Insertion order |
LinkedList |
Adding or removing elements at the beginning or end | Insertion order |
Sets store unique values and do not allow duplicates.
| Collection | Best known for | Ordering |
|---|---|---|
HashSet |
Fast general-purpose uniqueness checks | No guaranteed iteration order |
LinkedHashSet |
Uniqueness while retaining insertion order | Insertion order |
TreeSet |
Uniqueness with automatic sorting | Sorted order |
Maps associate a unique key with a value.
| Collection | Best known for | Key ordering |
|---|---|---|
HashMap |
Fast general-purpose key-value lookup | No guaranteed iteration order |
LinkedHashMap |
Key-value lookup while retaining insertion order | Insertion order |
TreeMap |
Key-value lookup with sorted keys | Sorted order |
- Stack: Last In, First Out (LIFO). The most recently added item is removed first.
- Queue: First In, First Out (FIFO). The earliest added item is removed first.
- Java Development Kit (JDK) 8 or newer
- A terminal, command prompt, or Java-compatible IDE
No third-party libraries, build tools, or database setup are required. Every example uses classes from the standard Java library.
Check your Java installation with:
java -version
javac -versionOpen a terminal in the repository directory and compile the file you want to explore:
javac T1_ArrayList.java
java T1_ArrayListReplace T1_ArrayList with any class name from the course roadmap.
On macOS or Linux:
javac *.javaOn Windows PowerShell:
javac *.javaRun any compiled lesson, for example:
java T8_TreeMapTo remove generated bytecode files after experimenting:
Remove-Item *.classOn macOS or Linux, use:
rm *.class- Start with
ArrayListandLinkedListto understand sequence-based collections. - Compare
HashSet,LinkedHashSet, andTreeSetto see how uniqueness and ordering differ. - Practice key-value operations with
HashMap,LinkedHashMap, andTreeMap. - Learn LIFO and FIFO behavior with
StackandQueue. - Finish with
T11_Important_Methods.javaand apply utility methods to a list. - Modify the values, add new elements, and predict the output before running each program.
After completing the examples, try these small extensions:
- Change the examples from
Integervalues toStringvalues. - Add duplicate values and observe how lists and sets respond differently.
- Insert map entries in a different order and compare
HashMap,LinkedHashMap, andTreeMap. - Add a
for-eachloop to every collection example. - Add a
containsValuecheck to the map examples. - Build a simple task manager using a
Queue. - Build a browser-history simulation using a stack.
- Sort a custom list in ascending and descending order.
java-collections-course/
├── T1_ArrayList.java
├── T2_LinkedList.java
├── T3_HashSet.java
├── T4_LinkedHashSet.java
├── T5_TreeSet.java
├── T6_HashMap.java
├── T7_LinkedHashMap.java
├── T8_TreeMap.java
├── T9_Stack.java
├── T10_Queue.java
├── T11_Important_Methods.java
└── readme.md
This repository is a companion learning resource for the MK Code Club channel. The examples are intentionally simple and readable so that beginners can focus on the behavior of each collection, then build on the examples with their own experiments.
Learn by running the code, changing the code, and checking whether the output matches your prediction.
This repository is provided for learning and educational purposes.