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