Skip to main content

Posts

Showing posts with the label HashMap Internals

🧭 My Deep Dive Into HashMap Internals 🔑🪄

  👋 Everyone knows HashMap as “key & value”… but what’s inside? Honestly, I was also in that majority who just knew: 👉 “HashMap = key & value storage.” …and never cared how it actually works under the hood . But recently I got curious and explored it myself, and here’s what I learned 👇 (sharing in case it helps someone else too 💛). 🔧 HashMap, HashSet, HashTable — what do they use internally? All of them rely on a common concept: Hashing Technique ⚡ …but there’s more happening than I expected! 🏗️ How does Hashing work here? Think of it as splitting data into an array of buckets : ✅ Each bucket holds entries ( key → value ). ✅ When you insert, the hash function decides which bucket to drop your data into. ➡️ In Java: Your key’s hashCode() is used. That hash code is transformed into a bucket index. Inside that bucket, Java stores a Map.Entry (key and value pair). Why override hashCode() ? ✔️ To give a good distribution → fewer collisions → faste...