Here you can find the source of capitalizeFirstLetter(String string)
Parameter | Description |
---|---|
string | The string to be capitalized. |
public static String capitalizeFirstLetter(String string)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . ja v a 2 s. c o m * This method capitalizes the first character of the string. * @param string The string to be capitalized. * @return The new capitalized string. */ public static String capitalizeFirstLetter(String string) { /** * If the string isempty or null, * return the string itself. */ if (string.trim().isEmpty() || (string == null)) { return string; } else { /** * If not, then capitalize the first character and return the String. */ return Character.toUpperCase(string.charAt(0)) + string.substring(1); } } }