How to check if a String contains another String in a case insensitive manner in Java?

To check if a String contains another String in a case-insensitive manner in Java, you can use the toLowerCase() method of the String class and the contains() method.

Here is an example of how you can check if a String contains another String in a case-insensitive manner in Java:

String s1 = "Hello, World!";
String s2 = "world";

if (s1.toLowerCase().contains(s2.toLowerCase())) {
    System.out.println("s1 contains s2 (case-insensitive)");
}

In this example, the toLowerCase() method is used to convert both strings to lower case and the contains() method is used to check if one string contains the other.

Alternatively, you can use the equalsIgnoreCase() method to compare the strings in a case-insensitive manner:

if (s1.toLowerCase().equals(s2.toLowerCase())) {
    System.out.println("s1 is equal to s2 (case-insensitive)");
}

I hope this helps! Let me know if you have any questions.