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?
Asked
Active
Viewed 3,209 times
2
Jérôme Verstrynge
- 57,710
- 92
- 283
- 453
-
3Just leave them. Obsolete doesn't mean the same as not supported. – President James K. Polk Aug 14 '11 at 00:21
2 Answers
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:
HashMapis unsynchronized;HashMapcan containnulls.
So beware of these two when you swap in HashMap for HashTable.
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