IT科技

當前位置 /首頁/IT科技 > /列表

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
TAG標籤:javastartswith #