【发布时间】:2018-04-26 18:00:48
【问题描述】:
我有:
var schedulesByMonth = HashMap<String, MutableList<Schedule>>()
计划具有startDate: Date 属性。
我从Schedule 对象的巨大列表开始,并按月将它们分类到哈希图中。因此,如果 Schedule 对象上的 startDate 是 2018 年 6 月,它将进入键 June 2018 的列表。
这一切都很好,但我需要按月份正确排序的选择器的键:
schedulesByMonth.keys
如果该数组是["July 2018", "August 2018", "June 2018"],我需要它是["June 2018", "July 2018", "August 2018"]。
我知道我可以制作一个 sortedMap:
val sorted = schedulesByMonth.toSortedMap(compareBy<String> {
}
但这只会对键进行排序 (String)。如何使 it 成为值 (MutableList<Schedule>),以便我可以按其中一个时间表的 startDate 排序?
【问题讨论】: