📘 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

HashMapHashTable
not synchronized (faster)synchronized (slower)
allows one null keyno null key
modern, preferredlegacy 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 में अलग हैं।

तुलना

HashMapHashTable
not synchronized (तेज़)synchronized (धीमा)
एक null key allowednull key नहीं
modern, preferredlegacy class

सारांश

  • HashMap = तेज़, null allow, thread-safe नहीं।
  • HashTable = thread-safe, no null, legacy। HashMap use करें (threads को ConcurrentHashMap)।
← Back to Java Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n