data class User(
val name: String,
val address: Address,
val group: String
)
data class Address(
val street: String,
val city: String
)
I have a list of users. I need to order this list by custom order as per guidelines in Kotlin (or Java).
First order by
groupas below group order. (It's not alphabetical order)- Maths
- Science
- English
- other all values in the bottom without order
Then order by
cityas below city order. (It's not in alphabetical order)- Sydney
- Adelaide
- Melbourne
- other all values in the bottom without order
Then order by
streetin reverse alphabetical orderThen order by
namein alphabetical order
How can I write Comparator or custom method to order list as per above guidelines?
Address class can move into User class if needed.
you need to implement Comparable in class User like so