📘 Lesson · Lesson 39
HashMap vs HashTable
HashMap vs HashTable
Two Key-Value Stores
Both store key-value pairs, but differ in thread-safety and null handling.
Comparison
| HashMap | HashTable |
|---|---|
| not synchronized (faster) | synchronized (slower) |
| allows one null key | no null key |
| modern, preferred | legacy class |
Summary
- HashMap = faster, allows null, not thread-safe.
- HashTable = thread-safe, no null, legacy. Use HashMap (or ConcurrentHashMap for threads).
दो Key-Value Stores
दोनों key-value pairs रखती हैं, पर thread-safety और null handling में अलग हैं।
तुलना
| HashMap | HashTable |
|---|---|
| not synchronized (तेज़) | synchronized (धीमा) |
| एक null key allowed | null key नहीं |
| modern, preferred | legacy class |
सारांश
- HashMap = तेज़, null allow, thread-safe नहीं।
- HashTable = thread-safe, no null, legacy। HashMap use करें (threads को ConcurrentHashMap)।