Java String Ends With endsWith(String receiver, String... needles)

Here you can find the source of endsWith(String receiver, String... needles)

Description

ends With

License

Open Source License

Declaration

public static boolean endsWith(String receiver, String... needles) 

Method Source Code

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

public class Main {
    public static boolean endsWith(String receiver, String... needles) {
        return endsWith(receiver, false, needles);
    }/*from w w  w .j  ava  2  s  . co  m*/

    public static boolean endsWith(String receiver, boolean ignoreCase, String... needles) {
        if (receiver == null)
            return false;

        for (String needle : needles) {
            if (endsWith(receiver, ignoreCase, needle)) {
                return true;
            }
        }
        return false;
    }

    public static boolean endsWith(CharSequence receiver, String suffix, boolean ignoreCase) {
        return receiver.length() >= suffix.length() && regionMatches(receiver, receiver.length() - suffix.length(),
                suffix, 0, suffix.length(), ignoreCase);
    }

    public static boolean regionMatches(CharSequence receiver, int thisOffset, String other, int otherOffset,
            int length, boolean ignoreCase) {
        if (ignoreCase) {
            for (int i = 0; i < length; i++) {
                if (Character.toLowerCase(receiver.charAt(i + thisOffset)) != Character
                        .toLowerCase(other.charAt(i + otherOffset)))
                    return false;
            }
        } else {
            for (int i = 0; i < length; i++) {
                if (receiver.charAt(i + thisOffset) != other.charAt(i + otherOffset))
                    return false;
            }
        }
        return true;
    }
}

Related

  1. endsWith(String filePath, String extension)
  2. endsWith(String fullString, String subString)
  3. endsWith(String haystack, String needle)
  4. endsWith(String in, String str)
  5. endsWith(String inEnd, String inValue)
  6. endsWith(String s, char c)
  7. endsWith(String s, String end)
  8. endsWith(String s, String end)
  9. endsWith(String s, String end)