I converted my Java files to Kotlin. And I fixed most of them. However, I don't understand this part using Comparator
.
wordItems.sortWith(Comparator { (_, word), (_, word) ->
val size1 = word!!.length
val size2 = word.length
if (size1 < size2) {
return@Collections.sort - 1
} else if (size1 == size2) {
return@Collections.sort 0
} else {
return@Collections.sort 1
}
})
And this one also, I don't understand.
Collections.sort(wordItems) { (_, word), (_, word) ->
val size1 = word!!.length
val size2 = word.length
if (size1 < size2) {
return@Collections.sort - 1
} else if (size1 == size2) {
return@Collections.sort 0
} else {
return@Collections.sort 1
}
}
How can I change this to make it work?