如何在 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
廣告