如何在 Java 中以不区分大小写的方式检查一个字符串是否包含另一个字符串?

java 8object oriented programmingprogramming更新于 2025/4/24 7:07:17

一种方法是使用 toLowerCase()toUpperCase() 方法将两个字符串都转换为小写或大写,然后进行测试。

示例

public class Sample {
   public static void main(String args[]){
      String str = "Hello how are you welcome to Tutorialspoint";
      String test = "tutorialspoint";
      Boolean bool = str.toLowerCase().contains(test.toLowerCase());
      System.out.println(bool);
   }
}

输出

true

相关文章