Scala List lastIndexOf() method with example
The lastIndexOf() method is utilized to find the index of the last occurrence of the element present in this method as argument.
Method Definition: def lastIndexOf(elem: A, end: Int): Int
Return Type: It returns the index of the last occurrence of the element present in this method as argument.
Example #1:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 3 , 6 , 2 , 9 , 21 , 9 )
val result = m 1 .lastIndexOf( 9 )
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 3 , 6 , 2 , 9 , 3 , 21 , 3 )
val result = m 1 .lastIndexOf( 3 )
println(result)
}
}
|
Last Updated :
29 Jul, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...