Scala, find largest list in a list
假设 val a = List[List[int]]:
在 Scala 中查找包含最多元素的列表的最简洁方法是什么?
尝试 .maxBy 或 .maxByOption
之一
1
2 3 |
List(List(0)).maxBy(_.size) // List(0)
List(List(0)).maxByOption(_.size) // Some(List(0)) List.empty[List[Int]].maxByOption(_.size) // None |
1
|
List(List(1), List(2, 3)).maxBy(_.size)
|
来源:https://www.codenong.com/61913523/