最佳答案
如何创建具有相同元素 n 次的列表?
手动执行:
scala> def times(n: Int, s: String) =
| (for(i <- 1 to n) yield s).toList
times: (n: Int, s: String)List[String]
scala> times(3, "foo")
res4: List[String] = List(foo, foo, foo)
是否也有一种内置的方式来做同样的事情?