Java String Starts Wtih startsWith(String str, String prefix)

Here you can find the source of startsWith(String str, String prefix)

Description

 StringUtilities.startsWith(null, null)      = true StringUtilities.startsWith(null, "abc")     = false StringUtilities.startsWith("abcdef", null)  = false StringUtilities.startsWith("abcdef", "abc") = true StringUtilities.startsWith("ABCDEF", "abc") = false 

License

Apache License

Declaration

public static boolean startsWith(String str, String prefix) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/* w w  w. j  a v a 2  s . c om*/
     * <pre>
     * StringUtilities.startsWith(null, null)      = true
     * StringUtilities.startsWith(null, "abc")     = false
     * StringUtilities.startsWith("abcdef", null)  = false
     * StringUtilities.startsWith("abcdef", "abc") = true
     * StringUtilities.startsWith("ABCDEF", "abc") = false
     * </pre>
     */
    public static boolean startsWith(String str, String prefix) {
        return startsWith(str, prefix, false);
    }

    private static boolean startsWith(String str, String prefix, boolean ignoreCase) {
        if (str == null || prefix == null) {
            return (str == null && prefix == null);
        }
        if (prefix.length() > str.length()) {
            return false;
        }
        return str.regionMatches(ignoreCase, 0, prefix, 0, prefix.length());
    }
}

Related

  1. startsWith(String str, char prefix)
  2. startsWith(String str, char prefix)
  3. startsWith(String str, String mark, int paramInt)
  4. startsWith(String str, String prefix)
  5. startsWith(String str, String prefix)
  6. StartsWith(String str, String prefix)
  7. startsWith(String str, String prefix, boolean ignoreCase)
  8. startsWith(String str, String prefix, boolean ignoreCase)
  9. startsWith(String str, String prefix, int index)