Here you can find the source of capitalize(String str)
public static String capitalize(String str)
//package com.java2s; /**//w w w. ja va 2 s. c o m * Copyright 2010 ZTEsoft Inc. All Rights Reserved. * * This software is the proprietary information of ZTEsoft Inc. * Use is subject to license terms. * * $Tracker List * * $TaskId: $ $Date: 9:24:36 AM (May 9, 2008) $comments: create * $TaskId: $ $Date: 3:56:36 PM (SEP 13, 2010) $comments: upgrade jvm to jvm1.5 * * */ public class Main { public static String capitalize(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return str; } return new StringBuilder(strLen).append(Character.toTitleCase(str.charAt(0))).append(str.substring(1)) .toString(); } public static String toString(Object val) { if (val == null) { return ""; } return val.toString(); } public static String toString(Object[] objs) { if (objs != null && objs.length > 0) { StringBuffer buff = new StringBuffer(); for (int i = 0; i < objs.length; i++) { buff.append("\nItem[").append(i).append("]\n").append(objs[i]); } return buff.toString(); } else { return ""; } } public static String toString(int val) { return Integer.toString(val); } public static String toString(float val) { return Float.toString(val); } public static String toString(double val) { return Double.toString(val); } public static String toString(long val) { return Long.toString(val); } public static String toString(short val) { return Short.toString(val); } public static String toString(boolean val) { return Boolean.toString(val); } }