2

I have some old 3rd party Java code I am converting to Java 6. It contains HashTable instances, which are flagged as obsolete collections. What should I replace them with? What is the safest option?

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453

2 Answers2

6

Although not marked as deprecated in the API doc, HashTable is obsolete, you could consider use HashMap.

For the differences, you could check this post.

The main differences (the two that the doc said) are:

  1. HashMap is unsynchronized;

  2. HashMap can contain nulls.

So beware of these two when you swap in HashMap for HashTable.

Community
  • 1
  • 1
zw324
  • 26,764
  • 16
  • 85
  • 118
4

java.util.HashMap has very similar semantics, however it is not synchronized. If you depend on the synchronized behavior, you can use java.util.concurrent.ConcurrentHashMap

Yann Ramin
  • 32,895
  • 3
  • 59
  • 82