Java String Capitalize First capitalizeFirstLetter(final CharSequence chars)

Here you can find the source of capitalizeFirstLetter(final CharSequence chars)

Description

Capitalize the first letter of given CharSequence .

License

Apache License

Parameter

Parameter Description
chars chars to be processed

Return

char sequence with first letter capitalized

Declaration

static CharSequence capitalizeFirstLetter(final CharSequence chars) 

Method Source Code

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

public class Main {
    /**/*from ww  w.j a v  a  2 s .  c  o  m*/
     * Capitalize the first letter of given {@link CharSequence}.
     * If the first letter is already capitalized, the char sequence is returned directly.
     *
     * @param chars chars to be processed
     * @return char sequence with first letter capitalized
     */
    static CharSequence capitalizeFirstLetter(final CharSequence chars) {
        final char first = chars.charAt(0);
        if (Character.isUpperCase(first)) {
            return chars;
        } else {
            CharSequence following = chars.subSequence(1, chars.length());
            return String.valueOf(Character.toUpperCase(first)) + following;
        }
    }
}

Related

  1. capitalizeFirstCharacter(String value)
  2. capitalizeFirstCharacters(String whole)
  3. capitalizeFirstCharacterString(String item)
  4. capitalizeFirstCharOfString(final String input)
  5. capitalizeFirstLeter(String sentence)
  6. capitalizeFirstLetter(final String aString)
  7. capitalizeFirstLetter(final String s)
  8. capitalizeFirstLetter(final String variableName)
  9. capitalizeFirstLetter(String data)