How to sort objects list in case insensitive order?

It looks like compareBy might be able to take a Comparator as an argument, see the documentation here: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.comparisons/compare-by.html

Try:

places.sortWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.name }))

or

places.sortWith(compareBy(String.CASE_INSENSITIVE_ORDER, Place::name))

to sort the list in place, or you can assign it to a new variable using

val newList = places.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.name }))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)