Anonymous object as a comparator

Report a typo

We have a Person class with the name and age fields, as well as a list of several Person objects.

Sort the list by age using an anonymous object as a comparator.

Write a program in Kotlin
class Sorted{
data class Person(val name: String, val age: Int)

val people = listOf(
Person("Alice", 25),
Person("Bob", 20),
Person("Charlie", 30)
)

val sortedByAge = // make your code here
}
___

Create a free account to access the full topic