HashMap stores data as key-value pairs and uses a technique called hashing to find where to store and retrieve values almost instantly. When you put a key in, Java runs it through a hash function that converts it to an index in an internal array — that's where your value gets stored. Think of it like a library filing system — instead of searching every shelf, the system instantly tells you exactly which shelf your book is on based on its title.
Step 1 — you call put("Thomas", 95)
Step 2 — Java calls "Thomas".hashCode() // which returns some integer like 84324473
Step 3 — Java mods that by array size to get an index // 84324473 % 16 = 9 (default array size is 16)
Step 4 — stores the value at index 9
Step 5 — you call get("Thomas")
Step 6 — same hash function, same index 9
Step 7 — retrieves value instantly — O(1)
==========================================
// What if two keys hash to the same index?
// This is called a COLLISION
// Java handles it with a LinkedList (or Tree in Java 8+) // at that index — called a "bucket" // Index 9: Thomas(95) -> Alice(87) -> null
// (linked together in the same bucket)
// So worst case get() becomes O(n) if everything
// collides into one bucket — but this is very rare
Connection to your work: In your TEnmo app, tracking account balances by user ID is a classic HashMap use case — instant lookup by key. In your Tournament App, mapping team names to their records or scores would be another perfect fit.