If a string contains another string Ignore Case - Java java.lang

Java examples for java.lang:String Contain

Description

If a string contains another string Ignore Case

Demo Code

public class Main {

  public static void main(String[] argv) {
    String str = "java2s.com";
    String searchStr = "java2s.com";
    System.out.println(containsIgnoreCase(str, searchStr));
  }//ww w. java2  s .c om

  public static boolean containsIgnoreCase(String str, String searchStr) {
    if (str == null || searchStr == null) {
      return false;
    }
    return contains(str.toUpperCase(), searchStr.toUpperCase());
  }

  public static boolean contains(String str, char searchChar) {
    if (isEmpty(str)) {
      return false;
    }
    return str.indexOf(searchChar) >= 0;
  }

  public static boolean contains(String str, String searchStr) {
    if (str == null || searchStr == null) {
      return false;
    }
    return str.indexOf(searchStr) >= 0;
  }
  public static boolean isEmpty(String str) {
    return str == null || str.length() == 0;
  }

}

Related Tutorials