java 判斷字符串是否以指定字符串的字符開頭

1 ~ 寫在前面:
很多時候用過的東西不溫習就忘記了,到時候需要的時候還是需要百度,溫故而知新,說的真好!!

2~進入主題

Java判斷String是否以某個字符串開頭:

語法:
startWith(String prefix, int toffset)

prefix:指定的前綴

toffset:在字符串中查找的位置,可以省略,省略就從第一個下標開始查找


String   strTest= "helloWord";
System.out.println(strTest.startsWith("hello"));//輸出true
System.out.println(mobile.startsWith("helloY"));//輸出false
System.out.println(mobile.startsWith("hello",4));//輸出false

Java判斷String是否以某個字符串結尾:
endWith(String prefix, int toffset)

String strTest= "helloWord";
System.out.println(strTest.cc("Word"));//輸出true
System.out.println(strTest.endsWith("words"));//輸出false

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章