Java的LinkedHashMap是否保持键的顺序? [英] Does Java's LinkedHashMap maintain the order of keys?
本文介绍了Java的LinkedHashMap是否保持键的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当LinkedHashMap.keySet()被调用时,返回的Set的顺序与添加密钥的顺序是否相同?
When LinkedHashMap.keySet() is called, will the order of the Set returned be the same as the order the keys were added in?
推荐答案
是的。
请参阅: LinkedHashMap :
此链接列表定义迭代
订单,通常是将
地图(插入顺序)插入的订单
。
This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order).
,并从 HashMap# keySet 文档:
集合[返回]由地图支持,因此
更改为地图反映在
中,反之亦然。
The set [returned] is backed by the map, so changes to the map are reflected in the set, and vice-versa.
这篇关于Java的LinkedHashMap是否保持键的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文