LinkedHashMap中的entrySet()是否也保证了订单? [英] Does entrySet() in a LinkedHashMap also guarantee order?

查看:72
本文介绍了LinkedHashMap中的entrySet()是否也保证了订单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当有人试图访问时,我正在使用linkedHashMap来保证订单。但是,当需要迭代它时,使用entrySet()来返回键/值对保证顺序吗?迭代时不会进行任何更改。

I am using a linkedHashMap to guarantee order when someone tries to access it. However, when it comes time to iterate over it, does using entrySet() to return key/value pairs guarantee order as well? No changes will be made while iterating.

编辑:此外,通过迭代其键来迭代地图是否有任何不利影响打电话给?

Also, are there any adverse effects from iterating through the map by iterating through its keys and calling get?

推荐答案

根据 Javadocs ,是的。


此实现与 HashMap ,因为它维护一个双向链表,运行所有条目。此链接列表定义迭代排序,通常是键插入映射的顺序(插入顺序)。

This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order).

至于编辑,不,它应该工作得很好。但是入口集有点快,因为它避免了在迭代期间查找地图中每个键的开销。

As for the edit, no, it should work just fine. But the entry set is somewhat faster since it avoids the overhead of looking up every key in the map during iteration.

这篇关于LinkedHashMap中的entrySet()是否也保证了订单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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