A HashMap stores key–value pairs in buckets. It uses key.hashCode() to pick a bucket, and equals() to find the right key inside that bucket. Collisions are kept in a list/tree; when the load factor threshold is exceeded it resizes and rehashes to keep average lookups near O(1).
Expanding on the short answer — what usually matters in practice:
A tiny example (an explanation template):
// Example: discuss trade-offs for "how-does-a-hashmap-work-internally?"
function explain() {
// Start from the core idea:
// It uses a hash function to compute an index into an array of buckets. Collisions are handl
}