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) { StringBuilder cap = new StringBuilder(); text = text.replace("_", " "); for (String t : text.split(" ")) { if (t.length() > 2) { cap.append(t.substring(0, 1).toUpperCase()).append(t.substring(1).toLowerCase()).append(" "); } else { cap.append(t).append(" "); }//from w ww . j a v a 2s . com } return cap.substring(0, cap.length() - 1); } }