Java String Capitalize First capitalizeFirstCharacter(final String s)

Here you can find the source of capitalizeFirstCharacter(final String s)

Description

Capitalizes the first character of the given string.

License

Open Source License

Parameter

Parameter Description
s The string to capitalize.

Return

The given string with the first character capitalized.

Declaration

public static String capitalizeFirstCharacter(final String s) 

Method Source Code

//package com.java2s;
/*/*from   www  . j  a  v a 2s.co m*/
 * File:                Strings.java
 * Authors:             Justin Basilico
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry
 *
 * Copyright August 23, 2007, Sandia Corporation.  Under the terms of Contract
 * DE-AC04-94AL85000, there is a non-exclusive license for use of this work by
 * or on behalf of the U.S. Government. Export of this program may require a
 * license from the United States Government. See CopyrightHistory.txt for
 * complete details.
 *
 *
 */

public class Main {
    /**
     * Capitalizes the first character of the given string.
     * 
     * @param   s The string to capitalize.
     * @return  The given string with the first character capitalized.
     */
    public static String capitalizeFirstCharacter(final String s) {
        if (s == null) {
            return null;
        } else if (s.length() <= 0) {
            return "";
        } else {
            return s.substring(0, 1).toUpperCase() + s.substring(1);
        }
    }
}

Related

  1. capitalizeFirst(String toCapitalize)
  2. capitalizeFirstChar(final String str)
  3. capitalizeFirstChar(String name)
  4. capitalizeFirstChar(String name)
  5. capitalizeFirstChar(String s)
  6. capitalizeFirstCharacter(String s)
  7. capitalizeFirstCharacter(String s)
  8. capitalizeFirstCharacter(String str)
  9. capitalizeFirstCharacter(String str)