如何測試字串是否在 Java 中包含特定單詞?


只有且當此字串包含指定的字元值序列時,java.lang.String.contains() 方法才會返回 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-02-2020

2 千+ 檢視

開啟您的職業

完成課程以獲得認證

開始吧
廣告