sort object list kotlin
val dates = mutableListOf(
Date(2020, 4, 3),
Date(2021, 5, 16),
Date(2020, 1, 29)
)
println("--- ASC ---")
dates.sortWith(compareBy<Date> { it.year }.thenBy { it.month }.thenBy { it.day })
dates.forEach { println(it) }
sort object list kotlin
val dates = mutableListOf(
Date(2020, 4, 3),
Date(2021, 5, 16),
Date(2020, 1, 29)
)
println("--- ASC ---")
dates.sortWith(compareBy<Date> { it.year }.thenBy { it.month }.thenBy { it.day })
dates.forEach { println(it) }
sort custom object list in kotlin
val messages = mutableListOf<Message>(
Message(from = "Tonnie", messageString = "Hi", timestamp = Date()),
Message(from = "Victoria", messageString = "Miss You", timestamp = Date()))
messages.sortWith(compareBy { it.timestamp })
sort object list kotlin
val dates = mutableListOf(
Date(2020, 4, 3),
Date(2021, 5, 16),
Date(2020, 1, 29)
)
println("--- ASC ---")
val sortedDates = dates.sortedWith(compareBy<Date> { it.year }.thenBy { it.month }.thenBy { it.day })
dates.forEach { println(it) }
println("------")
sortedDates.forEach { println(it) }
sort object list kotlin
println("--- DESC ---")
val sortedDatesDescending =
dates.sortedWith(compareBy<Date> { it.year }.thenBy { it.month }.thenBy { it.day }).reversed()
dates.forEach { println(it) }
println("------")
sortedDatesDescending.forEach { println(it) }
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us