Here you can find the source of capitalizeFirst(String str)
Parameter | Description |
---|---|
str | - the string whose first letter to capitalize |
public static String capitalizeFirst(String str)
//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(); } }