Here you can find the source of capitalize(String text)
public static String capitalize(String text)
//package com.java2s; //License from project: Open Source License public class Main { public static String capitalize(String text) { if (text == null) return null; if (text.length() == 1) return text.toUpperCase(); String s = ""; for (int i = 0; i < text.length(); i++) if (i - 1 < 0 || text.charAt(i - 1) == ' ') s += ("" + text.charAt(i)).toUpperCase(); else/*from w w w . jav a2s . c om*/ s += ("" + text.charAt(i)).toLowerCase(); return s; } }