Extreme Java When vanilla Java is not enough

1Apr/110

Differences between HashMap and Hashtable

Fun facts about HashMap and Hashtable:

  1. Hashtable is thread-safe, HashMap isn't - that's something everybody knows;
  2. HashMap supports null keys and values - not so obvious, but very important;
  3. Enumerators returned from an Hashtable aren't fail-fast. Iterators from both classes are.

That was one of many questions I had to answer in a job interview. I admit I couldn't remember the second and third ones. I think I must study to upgrade my SCJP certification to refresh this kind of detail.

Filed under: Java SE Leave a comment