Java String Ends With endsWithIgnoreCase(final String input, final String suffix)

Here you can find the source of endsWithIgnoreCase(final String input, final String suffix)

Description

Checks if a string ends with a given suffix.

License

Creative Commons License

Parameter

Parameter Description
input string to check
suffix suffix to check

Exception

Parameter Description
IllegalArgumentException if Input or Suffix is null

Return

true if string ends with a given suffix

Declaration

public static boolean endsWithIgnoreCase(final String input, final String suffix) 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

public class Main {
    /**/*from   w  ww  . ja  v  a 2 s .  c  o  m*/
     * Checks if a string ends with a given suffix.
     * @param input string to check
     * @param suffix suffix to check
     * @return true if string ends with a given suffix
     * @throws IllegalArgumentException if Input or Suffix is null
     */
    public static boolean endsWithIgnoreCase(final String input, final String suffix) {
        if (input == null)
            throw new IllegalArgumentException("Input cannot be null!");
        if (suffix == null)
            throw new IllegalArgumentException("Suffix cannot be null!");
        return input.endsWith(suffix)
                || input.length() >= suffix.length() && input.toLowerCase().endsWith(suffix.toLowerCase());
    }
}

Related

  1. endsWithIC(String s1, String s2)
  2. endsWithIgnoreCase(final String base, final String end)
  3. endsWithIgnoreCase(final String base, final String end)
  4. endsWithIgnoreCase(final String haystack, final String needle)
  5. endsWithIgnoreCase(final String haystack, final String needle)
  6. endsWithIgnoreCase(final String source, final String target)
  7. endsWithIgnoreCase(final String str, final String end)
  8. endsWithIgnoreCase(final String string, final String end)
  9. endsWithIgnoreCase(final String text, final String suffix)