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

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

Description

Check if a String starts with a specified prefix character.

License

Open Source License

Parameter

Parameter Description
str the String to check, may be null
prefix the first char to find

Return

true, if the String starts with the prefix

Declaration

public static boolean startsWith(final String str, final char prefix) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from www  .ja va 2  s .  c o  m*/
     * Check if a String starts with a specified prefix character. <code>nulls</code> are handled
     * without exceptions. The comparison is case sensitive.
     * 
     * <pre>
     * StringUtil.startsWith(null, 'a')     = false
     * StringUtil.startsWith("", 0)         = false
     * StringUtil.startsWith("", 'a')       = false
     * StringUtil.startsWith("abcdef", 'a') = true
     * StringUtil.startsWith("ABCDEF", 'a') = false
     * StringUtil.startsWith("ABCDEF", 'B') = false
     * </pre>
     * 
     * @param str
     *            the String to check, may be null
     * @param prefix
     *            the first char to find
     * @return true, if the String starts with the prefix
     */
    public static boolean startsWith(final String str, final char prefix) {
        return str != null && str.length() > 0 && str.charAt(0) == prefix;
    }
}

Related

  1. startsWith(final String s, final String prefix, final boolean ignoreCase)
  2. startsWith(final String s, final String[] prefixes)
  3. startsWith(final String searchString, final String crit)
  4. startsWith(final String source, final String prefix)
  5. startsWith(final String src, final String sub)
  6. startsWith(final String str, final String... prefixes)
  7. startsWith(String baseString, String compareString)
  8. startsWith(String check, String doesStartWith)
  9. startsWith(String cid1, String cid2)