drop() method is method used by List to select all elements except first n elements of the list.
The following is the syntax of drop method.
def drop(n: Int): List[A]
Here, n is the number of elements to be dropped from the list. This method returns the all the elements of list except first n ones.
Below is an example program of showing how to use drop method −
object Demo { def main(args: Array[String]) = { val list = List(1, 2, 3, 4, 5) // print list println(list) //apply operation val result = list.drop(3) //print result println(result) } }
Save the above program in Demo.scala. The following commands are used to compile and execute this program.
\>scalac Demo.scala \>scala Demo
List(1, 2, 3, 4, 5) List(4, 5)