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

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

Description

Check if a String ends with a specified suffix character.

License

Open Source License

Parameter

Parameter Description
str the String to check, may be null
suffix the last char to find

Return

true, if the String ends with the suffix

Declaration

public static boolean endsWith(final String str, final char suffix) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w  w w. j  a  va  2 s .co m
     * Check if a String ends with a specified suffix character. <code>nulls</code> are handled
     * without exceptions. The comparison is case sensitive.
     * 
     * <pre>
     * StringUtil.endsWith(null, 'a')     = false
     * StringUtil.endsWith("", 0)         = false
     * StringUtil.endsWith("", 'a')       = false
     * StringUtil.endsWith("abcdef", 'f') = true
     * StringUtil.endsWith("ABCDEF", 'f') = false
     * StringUtil.endsWith("ABCDEF", 'G') = false
     * </pre>
     * 
     * @param str
     *            the String to check, may be null
     * @param suffix
     *            the last char to find
     * @return true, if the String ends with the suffix
     */
    public static boolean endsWith(final String str, final char suffix) {
        return str != null && str.length() > 0 && str.charAt(str.length() - 1) == suffix;
    }
}

Related

  1. endsWith(final CharSequence target, final CharSequence suffix)
  2. endsWith(final Object[] left, final Object[] right, final boolean equals)
  3. endsWith(final String path, final String suffix)
  4. endsWith(final String s, final String suffix, final boolean ignoreCase)
  5. endsWith(final String src, final String... suffixes)
  6. endsWith(final String str, final String... suffixes)
  7. endsWith(final String string, final String[] suffixes)
  8. endsWith(final StringBuilder builder, final char match)
  9. endsWith(int[] data, int[] ends)