带有示例的 Scala String endsWith() 方法
endsWith()方法用于检查指定的字符串是否以参数中指定的后缀结尾。
Method Definition: Boolean endsWith(String suffix)
Return Type: It returns true if the string ends with the suffix stated else it returns false.
示例 #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