如何在 Java 中以不区分大小写的方式检查一个字符串是否包含另一个字符串?
一种方法是使用 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP