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

Java 8Object Oriented ProgrammingProgramming

One way to do it to convert both strings to lower or upper case using toLowerCase() or toUpperCase() methods and test.

Example

Live Demo

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);
   }
}

Output

true
raja
Published on 12-Feb-2018 09:43:52
Advertisements