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


僅當此字串包含指定的 char 值序列時,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

更新於: 2020-02-26

2K+ 瀏覽

啟動職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.