Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the nth element of a Seq?

Tags:

scala

I want to get the nth element of a Seq, something like this:

val mySeq = Seq("A", "B", "C") mySeq.get(1) // Java syntax for List. This does not work. 
like image 736
Tom Wang Avatar asked Apr 14 '16 05:04

Tom Wang


1 Answers

mySeq.apply(1) is another way to say 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 
like image 106
Brian Avatar answered Oct 31 '22 01:10

Brian