我正在尝试在 Android 中创建一个消息传递应用程序,我需要根据我从 ZonedDateTime 对象创建的时间戳对消息进行排序。我打算用我用来重新创建 ZonedDateTime 对象的格式化程序解析时间戳字符串,但我需要能够按时间顺序对 ZonedDateTime 对象的数组列表进行排序。我怎样才能做到这一点?
sorted() 是对列表中的项目进行排序的方法。
sorted()
sort() 将对可变列表或数组进行排序。
sort()
在 Kotlin 文档中,暗示按自然顺序排序,这仅意味着该类需要实现Comparable接口。ZonedDateTime实现ChronoZonedDateTime哪些实现,Comparable所以这些方法应该工作。
Comparable
ZonedDateTime
ChronoZonedDateTime
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
点击生成二维码
我来说两句