Scala List drop() method with example
The drop() method belongs to the value member of the class List. It is utilized to select all the elements except the first n elements of the list.
Method Definition: def drop(n: Int): List[A]
Where, n is the number of elements to be dropped from the stated sequence.
Return Type: It returns all the elements of the list except the first n ones.
Example #1:
object GfG
{
def main(args : Array[String])
{
val list = List( "a" , "b" , "c" , "d" , "e" , "f" )
val result = list.drop( 4 )
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val list = List( 1 , 2 , 3 , 4 , 5 , 6 )
val result = list.drop( 2 )
println(result)
}
}
|
Last Updated :
13 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...