Java String Ends With endsWith(String s, String end)

Here you can find the source of endsWith(String s, String end)

Description

Returns true if the string ends with the string end.

License

Open Source License

Parameter

Parameter Description
s the string in which to search
end the string to check for at the end of the string

Return

true if the string ends with the string end; false otherwise

Declaration

public static boolean endsWith(String s, String end) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// w ww . j  a v  a 2s  .  c  o m
     * Returns <code>true</code> if the string ends with the specified character.
     * 
     * @param s the string in which to search
     * @param end the character to search for at the end of the string
     * @return <code>true</code> if the string ends with the specified character; <code>false</code> otherwise
     */
    public static boolean endsWith(String s, char end) {
        return endsWith(s, (new Character(end)).toString());
    }

    /**
     * Returns <code>true</code> if the string ends with the string <code>end</code>.
     * 
     * @param s the string in which to search
     * @param end the string to check for at the end of the string
     * @return <code>true</code> if the string ends with the string <code>end</code>; <code>false</code> otherwise
     */
    public static boolean endsWith(String s, String end) {
        if ((s == null) || (end == null)) {
            return false;
        }

        if (end.length() > s.length()) {
            return false;
        }

        String temp = s.substring(s.length() - end.length());

        if (temp.equalsIgnoreCase(end)) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. endsWith(String in, String str)
  2. endsWith(String inEnd, String inValue)
  3. endsWith(String receiver, String... needles)
  4. endsWith(String s, char c)
  5. endsWith(String s, String end)
  6. endsWith(String s, String end)
  7. endsWith(String s, String ending)
  8. endsWith(String s, String suffix)
  9. endsWith(String s1, String s2)