gpt4 book ai didi

java - 将项目添加到 LinkedHashMap 的顶部

转载 作者:行者123 更新时间:2023-11-30 08:18:40 25 4
gpt4 key购买 nike

我在我的代码中使用 LinkedHashMap。这是我的 map :

LinkedHashMap<String, Conversation> conversationsMap=new LinkedHashMap<String, Conversation>();

我正在使用以下行向这张 map 添加项目:

conversationsMap.put("test",Conversation);

但这行将项目添加到最后。我需要将此项目添加到这张 map 的顶部。我该怎么做?

最佳答案

LinkedHashMap 保留插入顺序。要将它添加到第一个,您需要遍历旧映射并在新映射中插入值。

关于java - 将项目添加到 LinkedHashMap 的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27348831/

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