如何在Java中以不区分大小写的方式检查字符串是否包含另一个字符串?
一种使用toLowerCase()或toUpperCase()方法并测试将字符串转换为小写或大写的方法。
示例
public class Sample { public static void main(String args[]){ String str = "Hello how are you welcome to Nhooo"; String test = "nhooo"; Boolean bool = str.toLowerCase().contains(test.toLowerCase()); System.out.println(bool); } }
输出结果
true