當前位置:生活全書館 >

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://shqsg.com/dianzi/z93w44.html
推薦文章