Java String Ends With endsWith(final CharSequence target, final CharSequence suffix)

Here you can find the source of endsWith(final CharSequence target, final CharSequence suffix)

Description

ends With

License

Open Source License

Declaration

public static boolean endsWith(final CharSequence target, final CharSequence suffix) 

Method Source Code

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

public class Main {

    public static boolean endsWith(final CharSequence target, final CharSequence suffix) {
        if (target == null || suffix == null) {
            return false;
        }//  w ww  .  j a v a 2 s .  c  om
        if (target == suffix) {
            return true;
        }
        final int suffixLength = suffix.length();
        final int targetLength = target.length();
        if (suffixLength > target.length()) {
            return false;
        }
        for (int i = 0; i < suffixLength; i++) {
            if (suffix.charAt(suffixLength - i - 1) != target.charAt(targetLength - i - 1)) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. endsWith(final boolean caseSensitive, final String text, final String suffix)
  2. endsWith(final byte[] big, final byte[] suffix)
  3. endsWith(final byte[] str1, int startIndex1, int endIndex1, final byte[] str2, int startIndex2, int endIndex2)
  4. endsWith(final CharSequence a, final CharSequence b)
  5. endsWith(final CharSequence str, final CharSequence suffix)
  6. endsWith(final Object[] left, final Object[] right, final boolean equals)
  7. endsWith(final String path, final String suffix)
  8. endsWith(final String s, final String suffix, final boolean ignoreCase)
  9. endsWith(final String src, final String... suffixes)