Here you can find the source of capitalize(final String str)
Parameter | Description |
---|---|
str | a parameter |
public static String capitalize(final String str)
//package com.java2s; //License from project: Apache License public class Main { /**// w ww. j a va 2s.co m * StringUtils.capitalize(null) = null * StringUtils.capitalize("") = "" * StringUtils.capitalize("cat") = "Cat" * StringUtils.capitalize("cAt") = "CAt" * StringUtils.capitalize("'cat'") = "'cat'" * * @param str * @return */ public static String capitalize(final String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return str; } final char firstChar = str.charAt(0); final char newChar = Character.toTitleCase(firstChar); if (firstChar == newChar) { // already capitalized return str; } char[] newChars = new char[strLen]; newChars[0] = newChar; str.getChars(1, strLen, newChars, 1); return String.valueOf(newChars); } }