Java String Ends With endsWith(final String src, final String... suffixes)

Here you can find the source of endsWith(final String src, final String... suffixes)

Description

Test to see if a given string ends with some suffixes.

License

Open Source License

Parameter

Parameter Description
src the source string to be tested
suffixes the set of suffixes

Return

true if src ends with the suffixes concatenated together

Declaration

public static boolean endsWith(final String src,
        final String... suffixes) 

Method Source Code

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

public class Main {
    /**/*from w  w  w. ja va  2 s.  co  m*/
     * Test to see if a given string ends with some suffixes. Avoids the cost
     * of concatenating the suffixes together
     *
     * @param src      the source string to be tested
     * @param suffixes the set of suffixes
     * @return true if src ends with the suffixes concatenated together
     */
    public static boolean endsWith(final String src,
            final String... suffixes) {
        int pos = src.length();

        for (int i = suffixes.length - 1; i >= 0; i--) {
            final String suffix = suffixes[i];
            pos -= suffix.length();
            if (!src.startsWith(suffix, pos)) {
                return false;
            }
        }
        return true;
    }
}

Related

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