Scala List indexOf() method with example Last Updated : 29 Jul, 2019 Improve Improve Like Article Like Save Share Report 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: // Scala program of indexOf() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list val m1 = List(3, 6, 2, 9, 21) // Applying indexOf method val result = m1.indexOf(9) // Displays output println(result) } } Output: 3 Example #2: // Scala program of indexOf() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list val m1 = List(3, 6, 2, 9, 21) // Applying indexOf method val result = m1.indexOf(3) // Displays output println(result) } } Output: 0 Like Article Suggest improvement Previous Scala List mkString() method with example Next Scala List lastIndexOf() method with example Share your thoughts in the comments Add Your Comment Please Login to comment...