javastartswith
- IT科技
- 關注:2.99W次
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
標籤:
javastartswith
- 文章版權屬於文章作者所有,轉載請註明 https://shqsg.com/dianzi/z93w44.html