Java String Ends With endsWithIgnoreCase(String str, String suffix)

Here you can find the source of endsWithIgnoreCase(String str, String suffix)

Description

 StringUtilities.endsWithIgnoreCase(null, null)      = true StringUtilities.endsWithIgnoreCase(null, "def")     = false StringUtilities.endsWithIgnoreCase("abcdef", null)  = false StringUtilities.endsWithIgnoreCase("abcdef", "def") = true StringUtilities.endsWithIgnoreCase("ABCDEF", "def") = true StringUtilities.endsWithIgnoreCase("ABCDEF", "cde") = false 

License

Apache License

Declaration

public static boolean endsWithIgnoreCase(String str, String suffix) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*w ww  . j a va2s  .c  o  m*/
     * <pre>
     * StringUtilities.endsWithIgnoreCase(null, null)      = true
     * StringUtilities.endsWithIgnoreCase(null, "def")     = false
     * StringUtilities.endsWithIgnoreCase("abcdef", null)  = false
     * StringUtilities.endsWithIgnoreCase("abcdef", "def") = true
     * StringUtilities.endsWithIgnoreCase("ABCDEF", "def") = true
     * StringUtilities.endsWithIgnoreCase("ABCDEF", "cde") = false
     * </pre>
     */
    public static boolean endsWithIgnoreCase(String str, String suffix) {
        return endsWith(str, suffix, true);
    }

    /**
     * <pre>
     * StringUtilities.endsWith(null, null)      = true
     * StringUtilities.endsWith(null, "def")     = false
     * StringUtilities.endsWith("abcdef", null)  = false
     * StringUtilities.endsWith("abcdef", "def") = true
     * StringUtilities.endsWith("ABCDEF", "def") = false
     * StringUtilities.endsWith("ABCDEF", "cde") = false
     * </pre>
     */
    public static boolean endsWith(String str, String suffix) {
        return endsWith(str, suffix, false);
    }

    private static boolean endsWith(String str, String suffix, boolean ignoreCase) {
        if (str == null || suffix == null) {
            return (str == null && suffix == null);
        }
        if (suffix.length() > str.length()) {
            return false;
        }
        int strOffset = str.length() - suffix.length();
        return str.regionMatches(ignoreCase, strOffset, suffix, 0, suffix.length());
    }
}

Related

  1. endsWithIgnoreCase(String seq, String suffix)
  2. endsWithIgnoreCase(String source, String eq)
  3. endsWithIgnoreCase(String str, String suffix)
  4. endsWithIgnoreCase(String str, String suffix)
  5. endsWithIgnoreCase(String str, String suffix)
  6. endsWithIgnoreCase(String str, String suffix)
  7. endsWithIgnoreCase(String str, String suffix)
  8. endsWithIgnoreCase(String str, String suffix)
  9. endsWithIgnoreCase(String string, String suffix)