📜  带有示例的 Scala List lastIndexOf() 方法

📅  最后修改于: 2022-05-13 01:54:45.524000             🧑  作者: Mango

带有示例的 Scala List lastIndexOf() 方法

lastIndexOf()方法用于查找此方法中作为参数存在的元素的最后一次出现的索引。

示例 #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)
      
    }
} 
输出:
5

示例 #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)
      
    }
} 
输出:
6