Java String Ends With endsWithChar(String string, char suffix)

Here you can find the source of endsWithChar(String string, char suffix)

Description

Tests if this string ends with the specified suffix.

License

Open Source License

Parameter

Parameter Description
string the <code>String</code> to check
suffix the suffix to find

Return

true if the char is a suffix of the given String; false otherwise.

Declaration

public static boolean endsWithChar(String string, char suffix) 

Method Source Code

//package com.java2s;
// License as published by the Free Software Foundation; either

public class Main {
    /**//from w  w w .  ja  v  a  2  s. com
     * Tests if this string ends with the specified suffix.
     * <p/>
     * It is faster version of {@link String#endsWith(String)} optimized for one-character
     * suffixes at the expense of some readability. Suggested by SimplifyStartsWith PMD rule:
     * http://pmd.sourceforge.net/pmd-5.3.1/pmd-java/rules/java/optimizations.html#SimplifyStartsWith
     *
     * @param string the <code>String</code> to check
     * @param suffix the suffix to find
     * @return <code>true</code> if the <code>char</code> is a suffix of the given
     * <code>String</code>; <code>false</code> otherwise.
     */
    public static boolean endsWithChar(String string, char suffix) {
        return string.length() > 0 && string.charAt(string.length() - 1) == suffix;
    }
}

Related

  1. endsWithAnyIC(String str, String[] needles)
  2. endsWithBackslash(final String s)
  3. endsWithChar(CharSequence s, char suffix)
  4. endsWithChar(final String s, final char c)
  5. endsWithChar(String s, char c)
  6. endsWithChar(String string, int character)
  7. endsWithContinuationMarker(String line)
  8. endsWithCVC(String str)
  9. endsWithDigit(final String s)