久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網
      最全最豐富的資訊網站

      java中判斷字符串中是否包含某個特定字符串的方法有哪些

      java中判斷字符串中是否包含某個特定字符串的方法有哪些

      判斷一個字符串是否包含某個子串的n種方法:

      1、startsWith()方法

      2、contains()方法

      3、indexOf方法

      startsWith()方法

      這個方法有兩個變體,用于檢測字符串是否以指定的前綴開始。

      此方法定義的語法如下:

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

      參數說明:

      prefix – 要匹配的前綴。

      toffset – 從哪里開始尋找字符串。

      返回值:

      true和false

      相關視頻教程推薦:java學習視頻

      示例:

      import java.io.*;   public class Test{    public static void main(String args[]){       String Str = new String("Welcome to Yiibai.com");         System.out.print("Return Value :" );       System.out.println(Str.startsWith("Welcome") );         System.out.print("Return Value :" );       System.out.println(Str.startsWith("Tutorials") );         System.out.print("Return Value :" );       System.out.println(Str.startsWith("Yiibai", 11) );    } }

      contains方法

      java.lang.String.contains()

      方法返回true,當且僅當此字符串包含指定的char值序列。

      返回值:

      true和false

      示例如下:

      public static void main(String[] args) {           String str = "abc";           boolean status = str.contains("a");           if(status){             System.out.println("包含");           }else{             System.out.println("不包含");         }       }

      indexOf方法

      java.lang.String.indexOf()

      用途是在一個字符串中尋找一個字的位置,同時也可以判斷一個字符串中是否包含某個字符。

      返回值:

      int

      示例如下:

      public static void main(String[] args) {     String str1 = "abcdefg";     int result1 = str1.indexOf("ab");     if(result1 != -1){         System.out.println("字符串str中包含子串“ab”"+result1);     }else{         System.out.println("字符串str中不包含子串“ab”"+result1);     } }

      贊(0)
      分享到: 更多 (0)
      網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號