当前位置:懂科普 >

IT科技

> javastartswith

javastartswith

startsWith()方法是属于java下的一个方法,它主要是用于检测字符串是否以指定的前缀开始。

具体的语法格式为:

public boolean startsWith(String prefix,int toffset)


public boolean startsWith(String prefix)

参数:

prefix -- 前缀。

toffset -- 字符串中开始查找的位置。

返回值:

若是字符串以指定的前缀开始,那么返回 true;否则需要返回false。

javastartswith

参考范例:

示例代码:

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
标签: javastartswith
  • 文章版权属于文章作者所有,转载请注明 https://dongkepu.com/itkeji/7d3zgg.html
推荐文章