How Can I Check If A String In Java Contains A Substring (ignoring Case)?

In Java, you can use the contains() method in combination with the toLowerCase() method to check if a string contains a substring while ignoring case. Here is an example:

String mainString = "Hello World";
String subString = "worlD";

if (mainString.toLowerCase().contains(subString.toLowerCase())) {
    System.out.println("Substring found!");
} else {
    System.out.println("Substring not found!");

In this example, the toLowerCase() method is applied to both the main string and the substring before comparing them using the contains() method. By converting both strings to lowercase, case sensitivity is ignored and the method returns true if the substring is found, and false if it is not found.

About the Author Rex

I'm a passionate tech blogger with an insatiable love for programming! From my early days tinkering with code, I've delved into web dev, mobile apps, and AI. Sharing insights and tutorials with the world is my joy, connecting me to a global community of like-minded tech enthusiasts. Python holds a special place in my heart, but I embrace all challenges. Constantly learning, I attend tech conferences, contribute to open-source projects, and engage in code review sessions. My ultimate goal is to inspire the next generation of developers and contribute positively to the ever-evolving tech landscape. Let's code together!