Master advanced collections, functional programming with streams, and concurrent programming basics.
Learn HashMap/HashSet, lambda expressions, Stream API, and thread fundamentals.
HashMap<String, Integer> scores = new HashMap<>();put(key, value) - add/update entriesget(key) - retrieve value by keycontainsKey(key) - check if key existskeySet(), values(), entrySet() - iterateHashSet<String> names = new HashSet<>();add(element) - adds unique elements onlycontains(element) - check membershipremove(element) - remove elementhashCode() and equals() internally--- HashMap Demo ---
Scores: {Alice=95, Bob=87, Charlie=92}
Alice's score: 95
Contains Bob? true
All entries:
Alice -> 95
Bob -> 87
Charlie -> 92
--- HashSet Demo ---
Unique names: [Alice, Bob, Charlie]
Add duplicate 'Alice': false
Contains 'Bob'? true
After removing Bob: [Alice, Charlie]
HashMap<K, V> map = new HashMap<>();map.put("key", value); Get: map.get("key");for (Map.Entry<K,V> e : map.entrySet()) { }set.add() returns false if duplicateReview feedback below
import java.util.*;import java.util.stream.*;(params) -> expression - single expression(params) -> { statements; } - code blocklist.forEach(x -> System.out.println(x));filter(predicate) - select elements matching conditionmap(function) - transform each elementsorted() - sort elementscollect(Collectors.toList()) - gather resultsreduce() - combine elements into single resultlist.stream().filter(x -> x > 5).collect(Collectors.toList())list.stream().map(x -> x * 2).toList()list.stream().mapToInt(x -> x).sum()Original: [3, 1, 4, 1, 5, 9, 2, 6]
Filtered (>3): [4, 5, 9, 6]
Doubled: [8, 10, 18, 12]
Sorted: [4, 5, 6, 9]
Sum: 31
Names: [Alice, Bob, Charlie, David]
Names starting with 'A' or 'C': [Alice, Charlie]
Uppercase: [ALICE, CHARLIE]
(x) -> x * 2 or x -> x * 2.filter(x -> condition).map(x -> transform(x)).collect(Collectors.toList()).mapToInt(x -> x).sum()Review feedback below
class MyThread extends Thread { public void run() { } }run() method with thread logicclass MyRunnable implements Runnable { public void run() { } }Thread t = new Thread(new MyRunnable());start() - begin thread executionjoin() - wait for thread to completesleep(millis) - pause executiongetName() - get thread nameThread t = new Thread(() -> { /* code */ });Main thread starting...
Thread-A: Count 0
Thread-B: Count 0
Thread-A: Count 1
Thread-B: Count 1
Thread-A: Count 2
Thread-B: Count 2
Thread-A finished!
Thread-B finished!
Lambda thread running...
Main thread finished!
class MyThread extends Thread { public void run() { } }thread.start(); (NOT run() directly!)Thread.sleep(1000); in try-catchnew Thread(() -> { code });thread.join(); blocks until thread finishesReview feedback below