Here you can find the source of capitalize(String str)
public static String capitalize(String str)
//package com.java2s; public class Main { public static String capitalize(String str) { return changeFirstCharacterCase(str, true); }//from w w w . j av a 2 s.c om private static String changeFirstCharacterCase(String str, boolean capitalize) { if (str == null || str.length() == 0) { return str; } StringBuffer buf = new StringBuffer(str.length()); if (capitalize) { buf.append(Character.toUpperCase(str.charAt(0))); } else { buf.append(Character.toLowerCase(str.charAt(0))); } buf.append(str.substring(1)); return buf.toString(); } }