Java String Ends With endsWithIgnoreCase(final String haystack, final String needle)

Here you can find the source of endsWithIgnoreCase(final String haystack, final String needle)

Description

ends With Ignore Case

License

Open Source License

Declaration

public static boolean endsWithIgnoreCase(final String haystack, final String needle) 

Method Source Code

//package com.java2s;

public class Main {
    public static boolean endsWithIgnoreCase(final String haystack, final String needle) {
        if (haystack == null)
            throw new IllegalArgumentException("Parameter 'haystack' is null.");
        if (needle == null)
            throw new IllegalArgumentException("Parameter 'needle' is null.");

        final int nl = needle.length();
        final int hl = haystack.length();
        if (nl == hl) {
            return haystack.equalsIgnoreCase(needle);
        }//from w w w.j  av a2s . c  om

        if (nl > hl) {
            return false;
        }

        // Inspired by https://stackoverflow.com/a/19154150/
        final int toffset = hl - nl;
        return haystack.regionMatches(true, toffset, needle, 0, nl);
    }
}

Related

  1. endsWithGaps(final byte[] aFrag, final int numEndGaps)
  2. endsWithIC(String a, String b)
  3. endsWithIC(String s1, String s2)
  4. endsWithIgnoreCase(final String base, final String end)
  5. endsWithIgnoreCase(final String base, final String end)
  6. endsWithIgnoreCase(final String haystack, final String needle)
  7. endsWithIgnoreCase(final String input, final String suffix)
  8. endsWithIgnoreCase(final String source, final String target)
  9. endsWithIgnoreCase(final String str, final String end)