如何測試字串是否在 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
廣告