Java String endsWith()
方法測試此字串是否以指定的尾碼結尾。
語法
以下是此方法的語法 -
public boolean endsWith(String suffix)
參數
suffix
- 指定的字串尾碼。
返回值
如果參數表示的字元序列是該對象表示的字元序列的尾碼,則此方法返回true
; 否則返回false
。 請注意,如果參數為空字元串或等於此equals(Object)
方法確定的String對象,則結果為true
。
示例
public class Test {
public static void main(String args[]) {
String Str = new String("This is really not immutable!!");
boolean retVal;
retVal = Str.endsWith( "immutable!!" );
System.out.println("Returned Value = " + retVal );
retVal = Str.endsWith( "immu" );
System.out.println("Returned Value = " + retVal );
}
}
執行上面示例代碼,得到以下結果:
Returned Value = true
Returned Value = false
上一篇:
Java String類
下一篇:
Java快速入門