Java String Capitalize First capitalizeFirst(String str)

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

Description

capitalize First

License

Open Source License

Parameter

Parameter Description
str - the string whose first letter to capitalize

Return

a string with the first letter of the str capitalized

Declaration

public static String capitalizeFirst(String str) 

Method Source Code

//package com.java2s;
/*//from   w ww .  ja v a2 s.  co  m
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program 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
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If
 * not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * 
     * @param str - the string whose first letter to capitalize
     * @return a string with the first letter of the {@code str} capitalized
     */
    public static String capitalizeFirst(String str) {
        if (str == null || str.isEmpty())
            return str;

        final char[] arr = str.toCharArray();
        final char c = arr[0];

        if (Character.isLetter(c))
            arr[0] = Character.toUpperCase(c);

        return arr.toString();
    }
}

Related

  1. capitalizeFirst(String attribute)
  2. capitalizeFirst(String input)
  3. capitalizeFirst(String name)
  4. capitalizeFirst(String rawStr)
  5. capitalizeFirst(String s)
  6. capitalizeFirst(String str)
  7. capitalizeFirst(String str)
  8. capitalizeFirst(String str)
  9. capitalizeFirst(String str)