您好,欢迎来到意榕旅游网。
搜索
您的当前位置:首页javastartswith

javastartswith

来源:意榕旅游网

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

以上就是小编的分享了,希望能够帮助到大家。

Copyright © 2019- yrrf.cn 版权所有 赣ICP备2024042794号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务