Here you can find the source of capitalize(String in)
public static String capitalize(String in)
//package com.java2s; // it under the terms of the GNU General Public License as published by public class Main { /**/* w w w.j a v a 2 s. c o m*/ * Capitalize the first letter of a text. Example : capitalize("toto") * returns "Toto" */ public static String capitalize(String in) { return capitalize(in, false); } /** * Capitalize all words in a text. Result is trimmed, and all sequences of * white characters are replaced by a regular space: " ". * * @param in * @param all * @return "toto tata" gives "Toto Tata" */ public static String capitalize(String in, boolean all) { if (in == null || in.equals("")) return in; if (!all) return in.substring(0, 1).toUpperCase() + in.substring(1); else { StringBuffer out = new StringBuffer(""); for (String word : in.split("\\s+")) { out.append(" ").append(capitalize(word)); } return out.toString().trim(); } } }