Here you can find the source of capitalize(String str)
public static String capitalize(String str)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w . j a v a 2s . com*/ * Capitalize the first character in the string if necessary. */ public static String capitalize(String str) { if (str == null) { return str; } int strLen = str.length(); if (strLen == 0) { return str; } char first = Character.toTitleCase(str.charAt(0)); if (first == str.charAt(0)) { return str; } return new StringBuilder(strLen).append(first).append(str.substring(1)).toString(); } }