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快速入门