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:
// Scala program of lastIndexOf() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list val m1 = List(3, 6, 2, 9, 21, 9) // Applying lastIndexOf method val result = m1.lastIndexOf(9) // Displays output println(result) } } |
chevron_right
filter_none
Output:
5
Example #2:
// Scala program of lastIndexOf() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list val m1 = List(3, 6, 2, 9, 3, 21, 3) // Applying lastIndexOf method val result = m1.lastIndexOf(3) // Displays output println(result) } } |
chevron_right
filter_none
Output:
6
Recommended Posts:
- Scala String lastIndexOf() method with example
- Scala String lastIndexOf(int ch, int fromIndex)() method with example
- Scala String lastIndexOf(String str, int fromIndex) method with example
- Scala String lastIndexOf(String str) method with example
- Scala List map() method with example
- Scala List take() method with example
- Scala List contains() method with example
- Scala List min() method with example
- Scala List sum() method with example
- Scala List max() method with example
- Scala List apply() method with example
- Scala List product() method with example
- Scala List size() method with example
- Scala List filter() method with example
- Scala List takeWhile() method with example
- Scala List filterNot() method with example
- Scala List mkString() method with example
- Scala List takeRight() method with example
- Scala List addString() method with example
- Scala List drop() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

