String.StartsWith 方法


startsWith() 方法用於檢測字符串是否以指定的前綴開始。

   語法

public boolean startsWith(String prefix, int toffset)  public boolean startsWith(String prefix)

參數
  • prefix -- 前綴。

  • toffset -- 字符串中開始查找的位置。

返回值
如果字符串以指定的前綴開始,則返回 true;否則返回 falsepublic class Test {    

public static void main(String args[]) {        

    String Str = new String("www.abcd.com");         

    System.out.print("返回值 :" );        

    System.out.println(Str.startsWith("www") );         

    System.out.print("返回值 :" );       

    System.out.println(Str.startsWith("abcd") );         

    System.out.print("返回值 :" );       

    System.out.println(Str.startsWith("abcd", 4) ); 

}}

以上程序執行結果為:

返回值 :true
返回值 :false
返回值 :true

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM