Scala 字符串 endsWith()方法及示例
endsWith() 方法用于检查所述字符串是否以参数中所述的后缀结束。
方法定义。Boolean endsWith(String suffix)
返回类型。如果字符串以所述后缀结束,则返回真,否则返回假。
例子 #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
极客教程