Hi guys. I sort by alphabetical order items in lis...
# android
i
Hi guys. I sort by alphabetical order items in list by category name and it works but I want to have category "Other" always on the bottom. How Can I do that?
Copy code
enum class ItemCategory {
    ACCOUNT,
    CARD,
    OTHER,
    INVESTMENTS,
    LOAN
}
and then:
Copy code
items = itemList.sortedBy { it.category.name }.groupBy { it.category }
a
You could remove the items with category “OTHER” from the sorted itemlist and add them again at the end. Simple and straight forward!
✔️ 1
❤️ 1
e
also a custom comparator is easy to write:
Copy code
val comparator = compareBy<ItemCategory> { it == ItemCategory.OTHER }
    .thenBy { it.name }
items = itemList.groupBy { it.category }
    .toSortedMap(comparator)
❤️ 1
✔️ 1