Java String Starts Wtih startsWithChar(String string, char prefix)

Here you can find the source of startsWithChar(String string, char prefix)

Description

Tests if this string starts with the specified prefix.

License

Open Source License

Parameter

Parameter Description
string the <code>String</code> to check
prefix the prefix to find

Return

true if the char is a prefix of the given String; false otherwise.

Declaration

public static boolean startsWithChar(String string, char prefix) 

Method Source Code

//package com.java2s;
// License as published by the Free Software Foundation; either

public class Main {
    /**/*from  ww w .  j  av a  2s.  com*/
     * Tests if this string starts with the specified prefix.
     * <p/>
     * It is faster version of {@link String#startsWith(String)} optimized for one-character
     * prefixes at the expense of some readability. Suggested by SimplifyStartsWith PMD rule:
     * http://pmd.sourceforge.net/pmd-5.3.1/pmd-java/rules/java/optimizations.html#SimplifyStartsWith
     *
     * @param string the <code>String</code> to check
     * @param prefix the prefix to find
     * @return <code>true</code> if the <code>char</code> is a prefix of the given
     * <code>String</code>; <code>false</code> otherwise.
     */
    public static boolean startsWithChar(String string, char prefix) {
        return string.length() > 0 && string.charAt(0) == prefix;
    }
}

Related

  1. startsWithCamelCase(String string, String prefix)
  2. startsWithCapLettersEndsWithDigits(String text)
  3. startsWithChar(CharSequence s, char prefix)
  4. startsWithChar(final String s, final char c)
  5. startsWithChar(String s, char c)
  6. startsWithChar(String string, int character)
  7. startsWithCharacter(String str, char stringStart)
  8. startsWithCharacter(String str, String matchChars)
  9. startsWithCommonPackagePrefix(String inputText)