Java String Ends With endsWith(char s[], int len, char suffix[])

Here you can find the source of endsWith(char s[], int len, char suffix[])

Description

Returns true if the character array ends with the suffix.

License

Open Source License

Parameter

Parameter Description
s Input Buffer
len length of input buffer
suffix Suffix string to test

Return

true if s ends with suffix

Declaration

public static boolean endsWith(char s[], int len, char suffix[]) 

Method Source Code

//package com.java2s;
/*//from   ww w .  j a  v a 2  s .c  o m
 * Carrot2 project.
 *
 * Copyright (C) 2002-2016, Dawid Weiss, Stanis?aw Osi?ski.
 * All rights reserved.
 *
 * Refer to the full license file "carrot2.LICENSE"
 * in the root folder of the repository checkout or at:
 * http://www.carrot2.org/carrot2.LICENSE
 */

public class Main {
    /**
     * Returns true if the character array ends with the suffix.
     * 
     * @param s Input Buffer
     * @param len length of input buffer
     * @param suffix Suffix string to test
     * @return true if <code>s</code> ends with <code>suffix</code>
     */
    public static boolean endsWith(char s[], int len, String suffix) {
        final int suffixLen = suffix.length();
        if (suffixLen > len)
            return false;
        for (int i = suffixLen - 1; i >= 0; i--)
            if (s[len - (suffixLen - i)] != suffix.charAt(i))
                return false;

        return true;
    }

    /**
     * Returns true if the character array ends with the suffix.
     * 
     * @param s Input Buffer
     * @param len length of input buffer
     * @param suffix Suffix string to test
     * @return true if <code>s</code> ends with <code>suffix</code>
     */
    public static boolean endsWith(char s[], int len, char suffix[]) {
        final int suffixLen = suffix.length;
        if (suffixLen > len)
            return false;
        for (int i = suffixLen - 1; i >= 0; i--)
            if (s[len - (suffixLen - i)] != suffix[i])
                return false;

        return true;
    }
}

Related

  1. endsWith(byte[] bytes, String str)
  2. endsWith(byte[] dataFrom, String suffix)
  3. endsWith(byte[] source, char c)
  4. endsWith(byte[] subject, byte[] suffix)
  5. endsWith(char[] fieldDescriptor, char c)
  6. endsWith(CharSequence cs, CharSequence suffix)
  7. endsWith(CharSequence cs, String postfix)
  8. endsWith(CharSequence s, char c)