HashMap Internals & Collection Choice

KOTLIN › JVM Concurrency

HashMap internals, why sharing one breaks, and choosing the right collection on Android.

The classic live-coding trap is a thread-safe cache: interviewers check you know how HashMap works inside, what exactly goes wrong when threads share one, and which collection to reach for instead. The follow-ups are about the why, so be ready on visibility, happens-before, and check-then-act races. The Android-specific half matters too: SparseArray and ArrayMap trade asymptotic lookup for allocation savings, and a credible answer names both halves of that trade rather than treating them as a free win.

What this covers

Study this topic

Further reading