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