July 2017
Intermediate to advanced
796 pages
18h 55m
English
init selects all the elements in a Traversable collection but the last one. It can be defined formally as follows:
def init: Traversable[A]
Let's see an example as follows:
scala> List(1,2,3,4) initres7: List[Int] = List(1, 2, 3)
In Scala, if you want to select all elements except the first n elements, you should use drop. In the next subsection, we will see how to use drop.
Read now
Unlock full access