https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

Ayfri

02/09/2022, 10:13 PM
Just a quick question, is there any more simpler way to write
list.sortedBy { it }
, for a list of strings or numbers ? I know it's already pretty short but the fact that there's only
it
in the lambda feels kinda wrong
j

Joffrey

02/09/2022, 10:14 PM
list.sorted()
🙂 it's available not only for lists of integers but of any
Comparable
(see doc)
👍 2
e

ephemient

02/09/2022, 10:15 PM
also potentially useful is
list.sortedWith(Comparator.getInstance())
if you want locale-sensitive string sorting
a

Ayfri

02/09/2022, 11:38 PM
Dang I can't understand why I was not finding it but now I see it in the autocompletion, thanks :)
2 Views