如何在 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