如何测试字符串是否在 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.