开发者

Safest option to replace hashtable?

开发者 https://www.devze.com 2023-03-28 03:48 出处:网络
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开发者_Go百科 replace them with? What is the saf

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开发者_Go百科 replace them with? What is the safest option?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消