📜  带有示例的 Scala String endsWith() 方法

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

带有示例的 Scala String endsWith() 方法

endsWith()方法用于检查指定的字符串是否以参数中指定的后缀结尾。

示例 #1:

// Scala program of endsWith()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1= "Nidhi"
          
        // Applying endsWith() method
        val result = m1.endsWith("i")
          
        // Displays output
        println(result)
      
    }
} 
输出:
true

示例 #2:

// Scala program of endsWith()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1= "Nidhi"
          
        // Applying endsWith() method
        val result = m1.endsWith("y")
          
        // Displays output
        println(result)
      
    }
} 
输出:
false