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中方法重载和方法重写的区别
下一篇:无