String startsWith(String prefix, int toffset)
方法判斷字串是否以指定的首碼開始。
語法
以下是此方法的語法 -
public boolean startsWith(String prefix, int toffset)
參數
prefix
- 要匹配的首碼。toffset
- 從個索引位置開始匹配字串。
返回值
- 如果參數字元序列是該字串字元序列的首碼,則返回
true
; 否則返回false
。
示例
public class Test {
public static void main(String args[]) {
String Str = new String("Welcome to xuhuhu.com");
System.out.print("Return Value :");
System.out.println(Str.startsWith("Welcome"));
System.out.print("Return Value :");
System.out.println(Str.startsWith("zaixian", 11));
}
}
執行上面示例代碼,得到以下結果:
Return Value :true
Return Value :true
上一篇:
java中方法重載和方法重寫的區別
下一篇:無