Java endsWith() 方法
endsWith() 方法用於測試字串是否以指定的尾碼結束。
語法
public boolean endsWith(String suffix)
參數
suffix -- 指定的尾碼。
返回值
如果參數表示的字元序列是此對象表示的字元序列的尾碼,則返回 true;否則返回 false。注意,如果參數是空字元串,或者等於此 String 對象(用 equals(Object) 方法確定),則結果為 true。
實例
public class Test {
public static void main(String args[]) {
String Str = new String("IT研修:www.xuhuhu.com");
boolean retVal;
retVal = Str.endsWith( "zaixian" );
System.out.println("返回值 = " + retVal );
retVal = Str.endsWith( "com" );
System.out.println("返回值 = " + retVal );
}
}
以上程式執行結果為:
返回值 = false 返回值 = true