Java HashMap;值得推荐吗?
It has been reported that from Java JDK 1.3.1 to JDK 1.4.0
HashMap is 5 times slower (see
here).
What is the state of the art of HashMap at java 6?
Is recommendable to be used?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该错误在 1.4.0_02 和 1.4.1 中已被标记为已修复,因此可能无需担心其在 Java 1.6 中的性能。
(如果您处于多线程环境中,您可能需要 ConcurrrentHashMap。)
That bug is marked fixed in 1.4.0_02 and 1.4.1, so there probably isn't any need to worry about its performance in Java 1.6.
(If you're in a multithreaded environment, you probably want ConcurrrentHashMap.)
仅供您参考,如果还没有的话。hashmap 和 hashtable 之间的区别在于 hashtable 是同步的并且不允许 null 作为键,而且主要区别在于 hashmap 具有增强的哈希函数,可以防止两个不同的对象进入单个对象桶或防止哈希冲突。
Just for your information , if do not already.the difference between the hashmap and the hashtable is that hashtable is synchronized and does not allow null as key also the main difference is that hashmap has enhanced hash function thAt prevents two different object getting in to single bucket or to prevent Hash collision.
@苏雷什
说 HashMap 完全防止冲突是不正确的。事实上,在每个存储桶中,都有一个条目单链表的实现。所以,HashMap 中确实会发生冲突。我承认我不确定与哈希表相比的冲突百分比。
@Suresh
It is not correct to say that HashMap prevents collisions altogether. In fact, in each bucket, there lies an implementation of a singly linked-list of entries. So, collisions do happen in HashMap. I admit I'm not sure about the percentage of collisions as compared to Hashtable.