Java startsWith() 方法
startsWith() 方法用于檢測字符串是否以指定的前綴開始。
語法
public boolean startsWith(String prefix, int toffset) 或 public boolean startsWith(String prefix)
參數(shù)
prefix -- 前綴。
toffset -- 字符串中開始查找的位置。
返回值
如果字符串以指定的前綴開始,則返回 true;否則返回 false。
實例
public class Test { public static void main(String args[]) { String Str = new String("www.o2fo.com"); System.out.print("返回值 :" ); System.out.println(Str.startsWith("www") ); System.out.print("返回值 :" ); System.out.println(Str.startsWith("w3cschool") );
System.out.print("返回值 :" ); System.out.println(Str.startsWith("w3cschool", 4) );
} }
以上程序執(zhí)行結(jié)果為:
返回值 :true 返回值 :false 返回值 :true
更多建議: