我在我的代码中使用 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/