/** * <p>Check if a CharSequence starts with a specified prefix.</p> * * <p>{@code null}s are handled without exceptions. Two {@code null} * references are considered to be equal. The comparison is case sensitive.</p> * * <pre> * StringUtils.startsWith(null, null) = true * StringUtils.startsWith(null, "abc") = false * StringUtils.startsWith("abcdef", null) = false * StringUtils.startsWith("abcdef", "abc") = true * StringUtils.startsWith("ABCDEF", "abc") = false * </pre> * * @see java.lang.String#startsWith(String) * @param str the CharSequence to check, may be null * @param prefix the prefix to find, may be null * @return {@code true} if the CharSequence starts with the prefix, case sensitive, or * both {@code null} * @since 2.4 * @since 3.0 Changed signature from startsWith(String, String) to startsWith(CharSequence, CharSequence) */ public static boolean startsWith(final CharSequence str, final CharSequence prefix) { return startsWith(str, prefix, false); }
/** * <p>Case insensitive check if a CharSequence starts with a specified prefix.</p> * * <p>{@code null}s are handled without exceptions. Two {@code null} * references are considered to be equal. The comparison is case insensitive.</p> * * <pre> * StringUtils.startsWithIgnoreCase(null, null) = true * StringUtils.startsWithIgnoreCase(null, "abc") = false * StringUtils.startsWithIgnoreCase("abcdef", null) = false * StringUtils.startsWithIgnoreCase("abcdef", "abc") = true * StringUtils.startsWithIgnoreCase("ABCDEF", "abc") = true * </pre> * * @see java.lang.String#startsWith(String) * @param str the CharSequence to check, may be null * @param prefix the prefix to find, may be null * @return {@code true} if the CharSequence starts with the prefix, case insensitive, or * both {@code null} * @since 2.4 * @since 3.0 Changed signature from startsWithIgnoreCase(String, String) to startsWithIgnoreCase(CharSequence, CharSequence) */ public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix) { return startsWith(str, prefix, true); }