Tuesday, October 2, 2012

Difference Between Hashtable And HashMap

Hashtable :
  • Hashtable is thread-safe i.e. its methods are synchronized.
  • Hashtable does not allow null keys or null values.
  • Use Hashtable , when you need to have synchronization.

HashMap :
  • HashMap is not thread-safe or non-synchronized.
  • Performance-wise HashMap is more suitable as it does not have overheads of  threads.
  • HashMap allows one null key and any number of null values.