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