如何在 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-Feb-2020

已閱 117 次

開啟你的 職業生涯

完成課程以獲得認證

開始
廣告