What is the Difference Between a HashMap and a Hashtable in Java

  • Hashtableis synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.
  • Hashtabledoes not allow null keys or values. HashMap allows one null key and any number of null values.

One of HashMap’s subclasses is LinkedHashMap, so in the event that you’d want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for aLinkedHashMap. This wouldn’t be as easy if you were using Hashtable