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

117 次浏览

启动你的职业

通过完成课程获得认证

开始学习
广告
© . All rights reserved.