K.Os
K.Os

Reputation: 5496

How to sort by multiple fields using case sensitive

As simple sorting by two values in Kotlin can be like this:

.sortedWith(compareBy({ it.lastName }, { it.firstName }))

How to sort by those 2 field and adding case insensitive order? I know that this can be only applied to sorting by one field:

.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER, { it.lastName })

How to do this for both fields?

Upvotes: 1

Views: 1598

Answers (1)

Nongthonbam Tonthoi
Nongthonbam Tonthoi

Reputation: 12953

Not like this?

.sortedWith(compareBy({ it.lastName.toLowerCase() }, { it.firstName.toLowerCase() }))

Upvotes: 3

Related Questions