我试图根据键中的日期对这个 HashMap 进行排序
I trying to sort this HashMap based on date in keys
我的哈希图:
Map
使用 TreeMap 而不是 哈希映射.由于 Date 已经实现了 Comparable,插入时会自动排序.
Use a TreeMap instead of HashMap. As Date already implements Comparable, it will be sorted automatically on insertion.
Map<Date, ArrayList> m = new TreeMap<Date, ArrayList>();
或者,如果您有一个现有的 HashMap 并希望基于它创建一个 TreeMap,请将其传递给构造函数:
Alternatively, if you have an existing HashMap and want to create a TreeMap based on it, pass it to the constructor:
Map<Date, ArrayList> sortedMap = new TreeMap<Date, ArrayList>(m);
这篇关于如何根据日期对 HashMap 进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Couchbase 存储桶身份验证错误Couchbase Bucket authentication error(Couchbase 存储桶身份验证错误)
如何在 IntelliJ IDEA 中设置 SDK?How to setup SDK in IntelliJ IDEA?(如何在 IntelliJ IDEA 中设置 SDK?)
导入 com.google.android.gms.* 时出错;error importing com.google.android.gms.*;(导入 com.google.android.gms.* 时出错;)
无法从 Azure java SDK 列出图像发布者Cannot list image publishers from Azure java SDK(无法从 Azure java SDK 列出图像发布者)
我如何知道 Soundpool 已准备好使用低于 2.2 的 SDHow do I know that the Soundpool is ready using SDK target below 2.2?(我如何知道 Soundpool 已准备好使用低于 2.2 的 SDK 目标?)
什么是“已保存实例状态"?What is #39;savedInstanceState#39;?(什么是“已保存实例状态?)