mec*_*kos 1 scala list data-structures
例如,我有 val source = List("1", "2", "3", "4", "5", "6", "7")
,我需要从第二个元素开始得到3个元素.预期List("2","3")或List("3","4").有这种能力的方法或数据结构吗?
我认为slice这正是你要找的
scala> val source = List("1", "2", "3", "4", "5", "6", "7")
source: List[String] = List(1, 2, 3, 4, 5, 6, 7)
scala> source.slice(2, 4)
res0: List[String] = List(3, 4)
Run Code Online (Sandbox Code Playgroud)