Java HashMap;值得推荐吗?

发布于 2024-09-25 12:41:01 字数 212 浏览 1 评论 0原文

据报道,从Java JDK 1.3.1到JDK 1.4.0 HashMap 慢 5 倍(参见 此处)。

java 6 中 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阳光的暖冬 2024-10-02 12:41:01

该错误在 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.)

谁人与我共长歌 2024-10-02 12:41:01

仅供您参考,如果还没有的话。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.

月竹挽风 2024-10-02 12:41:01

@苏雷什
说 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文