Java String Ends With endsWithIgnoreCase(String s, String suffix)

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

Description

Check if a String ends with a specified suffix, ignoring case

License

Open Source License

Parameter

Parameter Description
s the String to check, may be null
suffix the suffix to find, may be null

Return

true if s ends with suffix or both s and suffix are null, false otherwise.

Declaration

public static boolean endsWithIgnoreCase(String s, String suffix) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /**//from ww  w  . j ava2 s.  com
     * Check if a String ends with a specified suffix, ignoring case
     *
     * @param s the String to check, may be null
     * @param suffix the suffix to find, may be null
     * @return true if s ends with suffix or both s and suffix are null, false
     *         otherwise.
     */
    public static boolean endsWithIgnoreCase(String s, String suffix) {
        if (s == null || suffix == null) {
            return (s == null && suffix == null);
        }
        if (suffix.length() > s.length()) {
            return false;
        }
        return s.regionMatches(true, s.length() - suffix.length(), suffix, 0, suffix.length());
    }
}

Related

  1. endsWithIgnoreCase(String haystack, String needle)
  2. endsWithIgnoreCase(String input, String suffix)
  3. endsWithIgnoreCase(String input, String... suffixes)
  4. endsWithIgnoreCase(String name, Iterable patterns)
  5. endsWithIgnoreCase(String p_sStr, String p_sSubStr)
  6. endsWithIgnoreCase(String s, String suffix)
  7. endsWithIgnoreCase(String s, String w)
  8. endsWithIgnoreCase(String seq, String suffix)
  9. endsWithIgnoreCase(String source, String eq)