What are the differences between Hashmap and Hashtable?

Asked

Viewed 1,858 times

9

What are the differences between HashMap and Hashtable in Java?

Which is more efficient?

  • Summarizing in a row: The Hashtable is synchronized (thread-safe). The Hashmap, no.

  • 1

    Consequently, if it is a situation without competition, in which either use one or the other, the non-synchronized version (Hashmap) will be more efficient.

1 answer

12


Hashmap

  • Is not synchronized
  • Accepts null values and a null key
  • It is possible to scan the entire structure with a simple iterator
  • Has containsValue() and containsKey()
  • Is faster
  • Consumes less memory
  • More modern
  • Mother: AbstractMap

Hashtable

  • Synchronized and can be easily used in concurrent environment
  • Does not accept null
  • Iterating is more complicated
  • Has contains()
  • Has overhead by synchronization
  • Takes up more memory
  • Considered obsolete
  • Mother: Dictionary

I withdrew the information mainly of that response in the OS.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.