Scala List dropRight() method with example
Last Updated :
26 Jul, 2019
The dropRight() method is utilized to find all the elements of the list except the last n elements.
Method Definition: def dropRight(n: Int): List[A]
Return Type: It returns all the elements of the list except the last n elements.
Example #1:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 1 , 1 , 3 , 3 , 3 , 5 , 4 , 5 , 2 )
val res = m 1 .dropRight( 3 )
println(res)
}
}
|
Output:
List(1, 1, 3, 3, 3, 5)
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 1 , 1 , 3 , 3 , 3 , 5 , 4 , 5 , 2 )
val res = m 1 .dropRight( 10 )
println(res)
}
}
|
Share your thoughts in the comments
Please Login to comment...