Maps and HashMap
LockedLesson 18 of 60 · DataStructures · Medium
Finish these first:Lists and Sets →Or pass the tests below to unlock it now.
The big idea
Map<K,V: HashMap (fast, unordered), LinkedHashMap (insertion order), TreeMap (sorted). Keys need correct equals/hashCode.
Think of it like this: Think of data structures as specialized toolboxes: a List keeps items in numbered slots (`0, 1, 2...`), a Set keeps only unique badges, and a Dictionary/Map labels each compartment with a custom name key.
Read the lesson
Map<K,V>: HashMap (fast, unordered), LinkedHashMap (insertion order), TreeMap (sorted). Keys need correct equals/hashCode.
Map<String,Integer> counts = new HashMap<>();
counts.merge("a", 1, Integer::sum);
counts.getOrDefault("b", 0);
Quick check
Before writing code: What should `Solution.countChars("aab")` return when your implementation of Maps and HashMap is working?
Your challenge
Write static Map<Character,Integer> countChars(String s).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.dicts (90% overlap). `dict` ~ `HashMap<K,V>`; `get(k, d)` ~ `getOrDefault`.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Maps and HashMap.
Learn this first
- Lists and SetsNot yet
Opens up next
This is the last lesson in this branch.