Java String Starts Wtih startsWith(String receiver, String... needles)

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

Description

starts With

License

Open Source License

Declaration

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

Method Source Code

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

public class Main {
    public static boolean startsWith(String receiver, String... needles) {
        return startsWith(receiver, false, needles);
    }/*w ww  .ja v  a  2 s  . co  m*/

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

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

    public static boolean startsWith(CharSequence receiver, String prefix, boolean ignoreCase) {
        return receiver.length() >= prefix.length()
                && regionMatches(receiver, 0, prefix, 0, prefix.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. startsWith(String inStart, String inValue)
  2. startsWith(String n, char tag)
  3. startsWith(String partial, String possible)
  4. startsWith(String path, String prefix)
  5. startsWith(String prefix, String string, boolean caseInsensitive)
  6. startsWith(String s, boolean caseIgnore, String... args)
  7. startsWith(String s, char begin)
  8. startsWith(String s, char c)
  9. startsWith(String s, int offset, int end, String t)