測(cè)試此字符串是否以指定的后綴結(jié)尾。
Boolean endsWith(String suffix)
后綴 - 要搜索的后綴
如果由參數(shù)表示的字符序列是由此對(duì)象表示的字符序列的后綴,則此方法返回true; 否則為假。 注意,如果參數(shù)是空字符串或等于由equals(Object)方法確定的此String對(duì)象,則結(jié)果將為true。
下面是一個(gè)使用這個(gè)方法的例子 -
class Example { static void main(String[] args) { String s = "HelloWorld"; println(s.endsWith("ld")); println(s.endsWith("lo")); println("Hello".endsWith("lo")); } }
當(dāng)我們運(yùn)行上面的程序,我們將得到以下結(jié)果 -
true false true
更多建議: