Scala Set takeRight() method with example
The takeRight() method is utilized to return a set consisting of last ‘n’ elements of the set.
Method Definition: def takeRight(n: Int):Set[A]
Where ‘n’ is specifies the number of elements to select.
Return Type: It returns a set consisting of last ‘n’ elements of the set.
Example #1:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 1 , 2 , 3 , 4 , 1 )
val result = s 1 .takeRight( 4 )
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 41 , 12 , 23 , 43 )
val result = s 1 .takeRight( 3 )
println(result)
}
}
|
Last Updated :
18 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...