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) { StringBuilder sb = new StringBuilder(str); for (int i = 0; i < sb.length(); i++) { if (i == 0 || Character.isWhitespace(sb.charAt(i - 1))) { sb.replace(i, i + 1, Character.toString(Character .toUpperCase(sb.charAt(i)))); }/* ww w. j a v a2 s. c o m*/ } return sb.toString(); } public static String replace(String originalString, String searchString, String replaceString) { StringBuilder sb = new StringBuilder(originalString); int index = sb.indexOf(searchString); while (index != -1) { sb.replace(index, index + searchString.length(), replaceString); index += replaceString.length(); index = sb.indexOf(searchString, index); } return sb.toString(); } }