
java startswith是怎样的呢?下面就让我们一起来了解一下吧:
startsWith()方法是属于java下的一个方法,它主要是用于检测字符串是否以指定的前缀开始。
具体的语法格式为:
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.runoob.com");
System.out.print("返回值 :" );
System.out.println(Str.startsWith("www") );
System.out.print("返回值 :" );
System.out.println(Str.startsWith("runoob") );
System.out.print("返回值 :" );
System.out.println(Str.startsWith("runoob", 4) );
}
}输出结果:
返回值 :true 返回值 :false 返回值 :true
以上就是小编的分享了,希望能够帮助到大家。
