Groovy - endsWith()
测试此字符串是否以指定的后缀结尾。
语法
Boolean endsWith(String suffix)
参数
Suffix – 要搜索的后缀
返回值
如果参数表示的字符序列是该对象表示的字符序列的后缀,则该方法返回true; 否则为假。 请注意,如果参数是空字符串或等于由 equals(Object) 方法确定的此 String 对象,则结果将为 true。
示例
以下是该方法的用法示例 −
class Example {
static void main(String[] args) {
String s = "HelloWorld";
println(s.endsWith("ld"));
println(s.endsWith("lo"));
println("Hello".endsWith("lo"));
}
}
当我们运行上面的程序时,会得到下面的结果 −
true false true

