測試此字符串是否以指定的後綴結尾。
用法
Boolean endsWith(String suffix)
參數
後綴 - 要搜索的後綴
返回值
如果參數所表示的字符序列是該對象所表示的字符序列的後綴,則該方法返回true;否則為假。請注意,如果參數是空字符串或等於由 equals(Object) 方法確定的此 String 對象,則結果將為真。
示例
以下是使用此方法的示例 -
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
相關用法
- Groovy exp()用法及代碼示例
- Groovy equals()用法及代碼示例
- Groovy eachMatch()用法及代碼示例
- Groovy equalsIgnoreCase()用法及代碼示例
- Groovy matches()用法及代碼示例
- Groovy after()用法及代碼示例
- Groovy padRight()用法及代碼示例
- Groovy contains()用法及代碼示例
- Groovy before()用法及代碼示例
- Groovy pow()用法及代碼示例
- Groovy sin()用法及代碼示例
- Groovy concat()用法及代碼示例
- Groovy random()用法及代碼示例
- Groovy Maps get()用法及代碼示例
注:本文由純淨天空篩選整理自 Groovy - endsWith()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。