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

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

Description

 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 

License

Apache License

Declaration

public static boolean endsWith(String str, String suffix) 

Method Source Code

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

public class Main {
    /**//from   w  ww .  j a  v a 2 s  . c om
     * <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. endsWith(String str, char suffix)
  2. endsWith(String str, char suffix)
  3. endsWith(String str, String end, boolean caseSensitive)
  4. endsWith(String str, String mark)
  5. endsWith(String str, String suffix)
  6. endsWith(String str, String suffix, boolean ignoreCase)
  7. EndsWith(String str, String suffix, int strStartPos)
  8. endsWith(String string, char character)
  9. endsWith(String string, String... end)