10) Collections: List, Set, Map
Goal
Use Java collections confidently and learn when to pick which.
List
- ordered
- allows duplicates
List<String> names = new ArrayList<>();
names.add("Asha");
names.add("Asha");
Set
- no duplicates
- order depends on implementation
Set<String> unique = new HashSet<>();
unique.add("Asha");
unique.add("Asha");
System.out.println(unique.size()); // 1
Map
Map<String, Integer> counts = new HashMap<>();
counts.put("apple", 2);
counts.put("apple", 3); // overwrites
Big-O intuition (very rough)
ArrayList random access: ~O(1)
ArrayList insert/remove in middle: ~O(n)
HashMap lookup by key: ~O(1) average
Exercises
- Count word frequency using
Map<String, Integer>.
- Remove duplicates from a list using a
Set.
- Sort a list of custom objects (create
Person(name, age) and sort by age).
Table of contents
- Getting Started: Install, run, and your first program
- Java Basics: types, variables, operators, formatting
- Control Flow: if/switch/loops
- Methods: parameters, return values, overloading
- OOP: classes, objects, encapsulation
- Inheritance & Polymorphism (and when not to use them)
- Interfaces, abstract classes, and design basics
- Exceptions and error handling
- Strings, files, and I/O basics
- Collections: List/Set/Map and Big-O intuition
- Generics (the useful parts)
- Lambdas & Streams
- Dates and time (java.time)
- Testing with JUnit 5 (basics)
- Concurrency: threads, executors, futures
- JVM basics: memory, GC, performance habits
- Build tools: Maven essentials (recommended)
- Next steps: projects to build