Java String Ends With endsWith(CharSequence cs, String postfix)

Here you can find the source of endsWith(CharSequence cs, String postfix)

Description

Returns whether cs ends with postfix.

License

Apache License

Parameter

Parameter Description
cs the string sequence to check for <code>postfix</code>
postfix the postfix to test for

Return

true if sb ends with postfix, false else

Declaration

public static boolean endsWith(CharSequence cs, String postfix) 

Method Source Code

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

public class Main {
    /**/*from w w w.j  av a  2 s.co  m*/
     * Returns whether <code>cs</code> ends with <code>postfix</code>.
     * 
     * @param cs the string sequence to check for <code>postfix</code>
     * @param postfix the postfix to test for
     * @return <code>true</code> if <code>sb</code> ends with 
     *   <code>postfix</code>, <code>false</code> else
     * 
     * @since 1.00
     */
    public static boolean endsWith(CharSequence cs, String postfix) {
        boolean match;
        int sbLen = cs.length();
        int pLen = postfix.length();
        if (sbLen >= pLen) {
            match = true;
            for (int p = pLen - 1, s = sbLen - 1; match && p >= 0; p--, s--) {
                match = postfix.charAt(p) == cs.charAt(s);
            }
        } else {
            match = false;
        }
        return match;
    }
}

Related

  1. endsWith(byte[] source, char c)
  2. endsWith(byte[] subject, byte[] suffix)
  3. endsWith(char s[], int len, char suffix[])
  4. endsWith(char[] fieldDescriptor, char c)
  5. endsWith(CharSequence cs, CharSequence suffix)
  6. endsWith(CharSequence s, char c)
  7. endsWith(CharSequence s, char c)
  8. endsWith(CharSequence s, CharSequence seq)
  9. endsWith(CharSequence s, CharSequence sub)