为什么HashMap不保证地图的顺序会随着时间的推移保持不变 [英] Why HashMap does not guarantee that the order of the map will remain constant over time

查看:185
本文介绍了为什么HashMap不保证地图的顺序会随着时间的推移保持不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里阅读有关Hashmap和Hashtable之间的区别: http://javarevisited.blogspot.sg/2010/10/difference -between-hashmap-and.html

I was reading about difference between Hashmap and Hashtable here: http://javarevisited.blogspot.sg/2010/10/difference-between-hashmap-and.html

任何人都可以阐明为什么它会说以下内容吗?

Can anyone throw some light on why it says following?

"5.HashMap不保证地图的顺序会随着时间的推移保持不变."

在重新哈希处理期间,顺序可以更改吗?

Could the order change during re-hashing, that is why?

如果您能将我引至资源或馆藏列表也很不错,这些馆藏或列表显示出不保证顺序保持不变的这种行为.

It would be also nice if you could point me to resource or list of collections who exhibit such behavior of not guaranteeing order to be remain constant.

AFIK,ArrayList提供了这样的保证(如果我错了,请告诉我)

AFIK, ArrayList gives such gurantee (let me know if I am wrong)

地图顺序" =可能是输入键或值的顺序.

'Order of map' = maybe order in which keys or values are entered.

推荐答案

A HashMap 没有订单-在任何时候.实际上,它不是用于此目的的.即使不进行哈希处理,顺序 也会发生变化.

A HashMap has no order - at any time. It is actually not used for that purpose. The order may change even when not rehashing.

如果您需要顺序保持不变,请使用 LinkedHashMap

If you need the order to remain constant, use a LinkedHashMap

这篇关于为什么HashMap不保证地图的顺序会随着时间的推移保持不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆