Java String Starts Wtih startsWithLetterOrUnderscore(String value)

Here you can find the source of startsWithLetterOrUnderscore(String value)

Description

starts With Letter Or Underscore

License

Open Source License

Declaration

public static boolean startsWithLetterOrUnderscore(String value) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011-2015 Red Hat, Inc.
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w w  w.j a v a  2  s . c om*/
 *     Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

public class Main {
    public static boolean startsWithLetterOrUnderscore(String value) {
        if (isEmpty(value)) {
            return false;
        }
        char character = value.charAt(0);
        return character == '_' || Character.isLetter(character);
    }

    /** 
     * Returns true if value is null or empty string.
     * @param value
     * @return
     */
    public static boolean isEmpty(String value) {
        return value == null || value.length() == 0;
    }

    public static boolean isEmpty(Object value) {
        return (value instanceof String) && isEmpty((String) value);
    }
}

Related

  1. startsWithIgnoreWhitespace(String str, String prefix)
  2. startsWithIgnoreWhitespaces(String prefix, String string)
  3. startsWithIndex(String[] prefixes, String fullPath)
  4. startsWithLenient(final String s, final String[] matches, final int[] minChars, final boolean acceptTrailing)
  5. startsWithLetter(String str)
  6. startsWithLinuxRoot(String path)
  7. startsWithLowerCase(String text)
  8. startsWithLowerCaseChar(String s)
  9. startsWithMultiple(String string, String... starts)