Common methods for all sequences

Common methods for all sequences

The following methods are provided by all sequence classes, that is by String, StringBuilder, Array, ArrayBuffer, List, and ListBuffer.

When the result is again a sequence, it is of the same type as the original sequence. So the take method of arrays returns an array, while the take method of strings returns a string.

You can use a for-loop to look at the elements of a sequence one-by-one:

scala> val L = List("CS109", "is", "the", "best")
L: List[java.lang.String] = List(CS109, is, the, best)
scala> for (i <- L)
     |   println(i)
This is called "iterating over a sequence" and is quite similar to the for-loop in Python.