Groovy endsWith()方法
测试此字符串是否以指定的后缀结尾。
句法
Boolean endsWith(String 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