Java endsWith() 方法
endsWith() 方法用于測(cè)試字符串是否以指定的后綴結(jié)束。
語(yǔ)法
public boolean endsWith(String suffix)
參數(shù)
suffix -- 指定的后綴。
返回值
如果參數(shù)表示的字符序列是此對(duì)象表示的字符序列的后綴,則返回 true;否則返回 false。注意,如果參數(shù)是空字符串,或者等于此 String 對(duì)象(用 equals(Object) 方法確定),則結(jié)果為 true。
實(shí)例
public class Test { public static void main(String args[]) { String Str = new String("W3Cschool教程:www.o2fo.com"); boolean retVal; retVal = Str.endsWith( "youj" ); System.out.println("返回值 = " + retVal ); retVal = Str.endsWith( "cn" ); System.out.println("返回值 = " + retVal ); } }
以上程序執(zhí)行結(jié)果為:
返回值 = false 返回值 = true
更多建議: