In Java, how do I check if a string contains a substring (ignoring case)?

trinity picture trinity · Feb 16, 2010 · Viewed 1.3M times · Source

I have two Strings, str1 and str2. How do I check if str2 is contained within str1, ignoring case?

Answer

Igor Artamonov picture Igor Artamonov · Feb 16, 2010
str1.toLowerCase().contains(str2.toLowerCase())