【发布时间】:2017-05-27 03:48:59
【问题描述】:
如何创建一个包含 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)
是否还有一种内置方法可以做到这一点?
【问题讨论】:
标签: scala