Java String endsWith()方法
阿新 • • 發佈:2019-02-03
描述
此方法測試字串是否以指定的字尾 suffix 結束。
語法
此方法定義的語法如下:
public boolean endsWith(String suffix)
返回值:
此方法如果引數所表示的字元序列是由該物件表示的字元序列的字尾返回true, 否則為false; 請注意,如果引數是空字串或等於此String物件由equals(Object)方法確定結果為 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
轉載地址:http://www.yiibai.com/java/java_string_endswith.html