Here you can find the source of capitalize(String s)
public static String capitalize(String s)
//package com.java2s; //License from project: Open Source License public class Main { public static String capitalize(String s) { if (s == null) { return null; }/*from w w w . ja v a 2 s. c om*/ String[] words = s.split(" "); StringBuffer buffer = new StringBuffer(); for (String word : words) { if (buffer.length() > 0) { buffer.append(' '); } buffer.append(capitalizeWord(word)); } return buffer.toString(); } private static String capitalizeWord(String s) { if (s.length() > 1) { return s.substring(0, 1).toUpperCase() + s.substring(1, s.length()).toLowerCase(); } return s.toUpperCase(); } }