是否可以通过其位置从 HashMap 中获取元素? [英] Is it possible to get element from HashMap by its position?

查看:19
本文介绍了是否可以通过其位置从 HashMap 中获取元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过位置从HashMap中检索元素,有可能吗?

How to retrieve an element from HashMap by its position, is it possible at all?

推荐答案

HashMaps 不保留排序:

这个类不保证地图的顺序;特别是,它不保证订单随着时间的推移将保持不变.

This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

看看 LinkedHashMap,这保证了可预测的迭代顺序.

Take a look at LinkedHashMap, which guarantees a predictable iteration order.

这篇关于是否可以通过其位置从 HashMap 中获取元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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