java startswith

奇闻趣事 2022-09-17 07:13生活趣事www.qiwenkd.com

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

上一篇:js 获取url参数 下一篇:vue publicpath

Copyright © 2014-2022 www.qiwenkd.com.奇闻网 版权所有

奇闻异事,飞碟,ufo,奇闻趣事,奇闻怪事,灵异事件,灵异故事,考古发现,恐怖事件,世界奇闻,宇宙奥秘,未解之谜,