【发布时间】:2020-04-07 21:42:40
【问题描述】:
我正在尝试对多个参数的列表进行排序。例如,一个值降序,第二个值升序,第三个值降序。
var people = listOf<People>(People("palazo", "ooo", 1),
People("asdf", "cccc", 2),
People("Maria", "ooo", 3),
People("Helena", "ccccc", 3),
People("Carlos", "ccc", 4),
People("Jhon", "ooo", 2)
)
有这样的方法吗? (我知道是不正确的) people = people.sortedByDescending {it.name}.thenBy{it.lastname}.thenDescending{it.age}
或添加到:
people.sortedWith(compareBy(People::name, People::lastName))
//but mixing ascending and descending
【问题讨论】:
-
你想达到什么目的?您能否详细说明并提供更多模型数据?
标签: sorting kotlin collections