ends With Ignore Case - Android java.lang

Android examples for java.lang:String Starts or Ends

Description

ends With Ignore Case

Demo Code

public class Main {

  /**//from  w w w .jav  a 2 s  .  c  o  m
   * Test if the given String ends with the specified suffix, ignoring upper/lower
   * case.
   * 
   * @param str
   *          the String to check
   * @param suffix
   *          the suffix to look for
   * @see String#endsWith
   */
  public static boolean endsWithIgnoreCase(String str, String suffix) {
    if (str == null || suffix == null) {
      return false;
    }
    if (str.endsWith(suffix)) {
      return true;
    }
    if (str.length() < suffix.length()) {
      return false;
    }

    String lcStr = str.substring(str.length() - suffix.length()).toLowerCase();
    String lcSuffix = suffix.toLowerCase();
    return lcStr.equals(lcSuffix);
  }

}

Related Tutorials