gpt4 book ai didi

java - Java 的 LinkedHashMap 是否维护键的顺序?

转载 作者:IT老高 更新时间:2023-10-28 20:47:38 24 4
gpt4 key购买 nike

调用LinkedHashMap.keySet()时,返回Set的顺序会和key的添加顺序一致吗?

最佳答案

是的。

见: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 - Java 的 LinkedHashMap 是否维护键的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3478061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com