如何在Scala中按两个字段对列表进行排序,在此示例中,我将按lastName和firstName进行排序?
case class Row(var firstName: String, var lastName: String, var city: String)
var rows = List(new Row("Oscar", "Wilde", "London"),
new Row("Otto", "Swift", "Berlin"),
new Row("Carl", "Swift", "Paris"),
new Row("Hans", "Swift", "Dublin"),
new Row("Hugo", "Swift", "Sligo"))
rows.sortBy(_.lastName)
我尝试这样的事情
rows.sortBy(_.lastName + _.firstName)
但这不起作用。因此,我对一个好的简单解决方案感到好奇。