Java String Capitalize First capitalizeFirst(String string)

Here you can find the source of capitalizeFirst(String string)

Description

Capitalize the first letter of the given string

License

Open Source License

Parameter

Parameter Description
string The string to have its first letter capitalized

Return

The string with its first letter capitalized or a blank string if string was null.

Declaration

public static String capitalizeFirst(String string) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w  .ja  v a 2 s. co m*/
 * net/balusc/util/StringUtil.java
 *
 * Copyright (C) 2007 BalusC
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Capitalize the first letter of the given string
     * @param string The string to have its first letter capitalized
     * @return The string with its first letter capitalized or a blank string
     * if string was null.
     */
    public static String capitalizeFirst(String string) {
        if (string != null) {
            return (string.substring(0, 1).toUpperCase() + string.substring(1, string.length()));
        } else {
            return "";
        }

    }
}

Related

  1. capitalizeFirst(String str)
  2. capitalizeFirst(String str)
  3. capitalizeFirst(String str)
  4. capitalizeFirst(String str)
  5. capitalizeFirst(String str)
  6. capitalizeFirst(String string)
  7. capitalizeFirst(String toCap)
  8. capitalizeFirst(String toCapitalize)
  9. capitalizeFirstChar(final String str)