我想获取Seq
的第n个元素,如下所示:
val mySeq = Seq("A", "B", "C")
mySeq.get(1) // Java syntax for List. This does not work.
最佳答案
mySeq.apply(1)
是另一种表达mySeq(1)
的方式
scala> val mySeq = Seq("A", "B", "C")
mySeq: Seq[String] = List(A, B, C)
scala> mySeq(0)
res0: String = A
scala> mySeq(1)
res1: String = B
关于scala - 如何获得Seq的第n个元素?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36614214/