如何在 Java 中判斷一個字串是否包含另一個字串?


java.lang.String.contains() 方法僅在且當該字串包含指定的 char 值序列時才返回 true。

示例

即時演示

public class Sample {
   public static void main(String args[]){
      String str = "Hello how are you welcome to tutorialspoint";
      String test = "tutorialspoint";
      Boolean bool = str.contains(test);
      System.out.println(bool);
   }
}

輸出

true

更新於: 26-2 月-2020

117 次瀏覽

啟動你的職業

透過完成課程獲得認證

開始學習
廣告